forked from microsoft/microsoft-ui-xaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomInlineTasks.targets
94 lines (86 loc) · 4.25 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?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>
<UsingTask Condition="$(BuildingWithBuildExe) == 'true'" TaskName="RunPowershellScript" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
<ParameterGroup>
<Path ParameterType="System.String" Required="true" />
<Parameters ParameterType="System.String" Required="false" />
<FilesWritten ParameterType="System.String[]" Required="false" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.Diagnostics" />
<Code Type="Fragment" Language="cs">
<![CDATA[
// pshrun.cmd is the script file to call if you want to execute a PowerShell script
// as part of a Razzle build.
string pshrunPath = Environment.GetEnvironmentVariable("RazzleToolPath") + "\\pshrun.cmd";
// We're passing a string as a script parameter twice (one to pshrun.cmd, one to pshrun.ps1),
// so we need to doubly-escape the string to make sure it survives both passages.
string pshrunParameters = Path + " " + Parameters.Replace("\"", "\"\"\"");
ProcessStartInfo processStartInfo = new ProcessStartInfo(pshrunPath, pshrunParameters);
processStartInfo.CreateNoWindow = true;
processStartInfo.UseShellExecute = false;
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processStartInfo.RedirectStandardOutput = true;
Log.LogMessage(string.Format("Running {0} {1}...", pshrunPath, pshrunParameters));
Process process = Process.Start(processStartInfo);
Console.WriteLine(process.StandardOutput.ReadToEnd());
// The bool "Success" is defined in codegen as the return value for inline MSBuild tasks such as this one.
Success = process.WaitForExit(60000) && process.ExitCode == 0;
process.Close();
if (!Success)
{
foreach (string filePath in FilesWritten)
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
}
}
]]>
</Code>
</Task>
</UsingTask>
</Project>