mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 06:23:24 -07:00
Use custom ApplyTokenReplacements task
This commit is contained in:
parent
1b39388294
commit
d4e9691011
1 changed files with 143 additions and 4 deletions
|
@ -1,7 +1,79 @@
|
||||||
<Project>
|
<Project>
|
||||||
|
<UsingTask TaskName="ApplyTokenReplacements" TaskFactory="CodeTaskFactory" AssemblyName="Microsoft.Build.Tasks.Core">
|
||||||
|
<ParameterGroup>
|
||||||
|
<InputLines ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
|
||||||
|
<Tokens ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
|
||||||
|
<OutputLines ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" />
|
||||||
|
</ParameterGroup>
|
||||||
|
<Task>
|
||||||
|
<Reference Include="System.Text.RegularExpressions" />
|
||||||
|
<Code Type="Fragment" Language="cs">
|
||||||
|
<![CDATA[
|
||||||
|
|
||||||
|
var output = new List<ITaskItem>();
|
||||||
|
|
||||||
|
foreach (var line in InputLines)
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
string text = line.ItemSpec;
|
||||||
|
|
||||||
|
foreach (var token in Tokens)
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
// Hole den Token-Namen (z. B. Box13_ClientId)
|
||||||
|
|
||||||
|
string tokenName = token.ItemSpec;
|
||||||
|
|
||||||
|
// Skip if tokenName is null or empty
|
||||||
|
if (string.IsNullOrEmpty(tokenName))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Log.LogMessage(MessageImportance.High, "Token name: "+tokenName);
|
||||||
|
|
||||||
|
Log.LogMessage(MessageImportance.High, "Token: "+ token);
|
||||||
|
|
||||||
|
// Hole den tatsächlichen Wert des Tokens, der ersetzt werden soll
|
||||||
|
|
||||||
|
string replacementValue = token.GetMetadata("ReplacementValue");
|
||||||
|
Log.LogMessage(MessageImportance.High, "replacementValue: "+ replacementValue);
|
||||||
|
|
||||||
|
// Ersetze das Token durch den Wert
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(replacementValue))
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
string placeholder = "$"+ "{"+tokenName+"}"; // Token-Format wie $(Box13_ClientId)
|
||||||
|
|
||||||
|
Log.LogMessage(MessageImportance.High, "placeholder: "+ placeholder);
|
||||||
|
|
||||||
|
text = text.Replace(placeholder, replacementValue);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
output.Add(new Microsoft.Build.Utilities.TaskItem(text));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
OutputLines = output.ToArray();
|
||||||
|
|
||||||
|
]]>
|
||||||
|
</Code>
|
||||||
|
</Task>
|
||||||
|
</UsingTask>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
<UsingTask TaskName="MSBuild.Community.Tasks.TemplateFile"
|
<UsingTask TaskName="MSBuild.Community.Tasks.TemplateFile"
|
||||||
AssemblyFile="$(NuGetPackageRoot)msbuildtasks/1.5.0.235/tools/MSBuild.Community.Tasks.dll" />
|
AssemblyFile="$(NuGetPackageRoot)msbuildtasks/1.5.0.235/tools/MSBuild.Community.Tasks.dll" />
|
||||||
|
-->
|
||||||
<PropertyGroup Condition="Exists('$(ProjectDir)$(ProjectName).Credentials.template')">
|
<PropertyGroup Condition="Exists('$(ProjectDir)$(ProjectName).Credentials.template')">
|
||||||
<MSBuildCommunityTasksPath>$(NuGetPackageRoot)msbuildtasks/1.5.0.235/tools/</MSBuildCommunityTasksPath>
|
<MSBuildCommunityTasksPath>$(NuGetPackageRoot)msbuildtasks/1.5.0.235/tools/</MSBuildCommunityTasksPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -10,6 +82,73 @@
|
||||||
|
|
||||||
<Target Name="ProcessTemplates" BeforeTargets="PrepareForBuild" Condition="Exists('$(ProjectDir)$(ProjectName).Credentials.template')">
|
<Target Name="ProcessTemplates" BeforeTargets="PrepareForBuild" Condition="Exists('$(ProjectDir)$(ProjectName).Credentials.template')">
|
||||||
<Message Text="Processing: $(ProjectDir)$(ProjectName).Credentials.template" Importance="high"/>
|
<Message Text="Processing: $(ProjectDir)$(ProjectName).Credentials.template" Importance="high"/>
|
||||||
<TemplateFile Template="$(ProjectDir)$(ProjectName).Credentials.template" OutputFilename="$(ProjectDir)$(ProjectName).Credentials.cs" Tokens="@(Tokens)" />
|
|
||||||
|
|
||||||
|
<ReadLinesFromFile File="$(ProjectDir)$(ProjectName).Credentials.template">
|
||||||
|
<Output TaskParameter="Lines" ItemName="TemplateLines" />
|
||||||
|
</ReadLinesFromFile>
|
||||||
|
|
||||||
|
<ApplyTokenReplacements InputLines="@(TemplateLines)" Tokens="@(Tokens)">
|
||||||
|
<Output TaskParameter="OutputLines" ItemName="ProcessedLines" />
|
||||||
|
</ApplyTokenReplacements>
|
||||||
|
|
||||||
|
<WriteLinesToFile
|
||||||
|
File="$(ProjectDir)$(ProjectName).Credentials.cs"
|
||||||
|
Lines="@(ProcessedLines)"
|
||||||
|
Overwrite="true" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
<ReadLinesFromFile File="$(ProjectDir)$(ProjectName).Credentials.template">
|
||||||
|
<Output TaskParameter="Lines" ItemName="TemplateLines" />
|
||||||
|
</ReadLinesFromFile>
|
||||||
|
|
||||||
|
<Message Text="Ersetze Umgebungsvariablen in Template..." Importance="High" />
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProcessedLines>
|
||||||
|
<Output>$([System.Text.RegularExpressions.Regex]::Replace('%(TemplateLines.Identity)', '\{\{API_KEY\}\}', '$(API_KEY)'))</Output>
|
||||||
|
</ProcessedLines>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<WriteLinesToFile
|
||||||
|
File="$(ProjectDir)$(ProjectName).Credentials.cs"
|
||||||
|
Lines="@(ProcessedLines->'%(Output)')"
|
||||||
|
Overwrite="true" />
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
<ReadLinesFromFile File="$(ProjectDir)$(ProjectName).Credentials.template">
|
||||||
|
<Output TaskParameter="Lines" ItemName="TemplateLines" />
|
||||||
|
</ReadLinesFromFile>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProcessedLines Include="@(TemplateLines)">
|
||||||
|
<Output1>$([System.String]::Copy('%(Identity)'))</Output1>
|
||||||
|
</ProcessedLines>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProcessedLines>
|
||||||
|
<Output1>$([System.Text.RegularExpressions.Regex]::Replace('%(Output1)', '\$\{Photobucket_ClientId\}', '$(Photobucket_ClientId)'))</Output1>
|
||||||
|
<Output1>$([System.Text.RegularExpressions.Regex]::Replace('%(Output1)', \$\{Photobucket_ClientSecret\}', '$(Photobucket_ClientSecret)'))</Output1>
|
||||||
|
</ProcessedLines>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<WriteLinesToFile
|
||||||
|
File="$(ProjectDir)$(ProjectName).Credentials.cs"
|
||||||
|
Lines="@(ProcessedLines->'%(Output1)')"
|
||||||
|
Overwrite="true" />
|
||||||
|
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue