forked from microsoft/microsoft-ui-xaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomInlineTasks.targets
46 lines (44 loc) · 1.97 KB
/
CustomInlineTasks.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Tasks that aren't very complex and don't need to be run in an isolated context can just be defined inline.
Tasks like that that we use are defined here. -->
<UsingTask TaskName="CopyWithReplacements" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
<ParameterGroup>
<SourceFiles ParameterType="System.String[]" Required="true" />
<DestinationFiles ParameterType="System.String[]" Required="true" />
<Patterns ParameterType="System.String[]" Required="true" />
<Replacements ParameterType="System.String[]" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="Microsoft.Build.Framework" />
<Code Type="Fragment" Language="cs">
<![CDATA[
if (SourceFiles.Length != DestinationFiles.Length)
{
Log.LogError("SourceFiles and DestinationFiles must be the same lengths.");
Success = false;
}
else if (Patterns.Length != Replacements.Length)
{
Log.LogError("Patterns and Replacements must be the same lengths.");
Success = false;
}
else
{
for (int i = 0; i < SourceFiles.Length; i++)
{
string text = File.ReadAllText(SourceFiles[i]);
for (int j = 0; j < Patterns.Length; j++)
{
text = text.Replace(Patterns[j], Replacements[j]);
}
File.WriteAllText(DestinationFiles[i], text);
}
}
]]>
</Code>
</Task>
</UsingTask>
</Project>