-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.targets
63 lines (61 loc) · 2.04 KB
/
Utils.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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="DownloadFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<Url ParameterType="System.String" Required="true" />
<LocalFilePath ParameterType="System.String" Required="true"/>
</ParameterGroup>
<Task>
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<Using Namespace="System.Net"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
try
{
var dirName = Path.GetDirectoryName(LocalFilePath);
if (dirName != null && Directory.Exists(dirName))
{
Directory.CreateDirectory(dirName);
}
using (WebClient client = new WebClient())
{
client.DownloadFile(Url, LocalFilePath);
}
}
catch(Exception ex)
{
Log.LogMessage(MessageImportance.High, string.Format("##teamcity[buildProblem description='{0}' identity='{0}']", ex.Message));
throw;
}
]]>
</Code>
</Task>
</UsingTask>
<UsingTask TaskName="Replace" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<FilePath ParameterType="System.String" Required="true"/>
<Pattern ParameterType="System.String" Required="true" />
<Replacement ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<Using Namespace="System.Linq"/>
<Using Namespace="System.Text.RegularExpressions"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
try
{
File.WriteAllLines(FilePath, File.ReadAllLines(FilePath).Select(line => Regex.Replace(line, Pattern, Replacement)).ToList());
}
catch(Exception ex)
{
Log.LogMessage(MessageImportance.High, string.Format("##teamcity[buildProblem description='{0}' identity='{0}']", ex.Message));
throw;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>