forked from Callisto82/tftp.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
78 lines (65 loc) · 2.7 KB
/
build.cake
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
using System.Text;
using System.Text.RegularExpressions;
var target = Argument("target", "Default");
var config = Argument("config", "Release");
var buildNumber = Argument("buildNumber", "0");
var fullVersion = $"2.0.0.{buildNumber}";
Task("Update-Version")
.Does(() =>
{
foreach (var csproj in GetFiles("**/*.csproj"))
{
Information($"Updating {csproj} to {fullVersion}...");
RegexReplaceInFile(csproj.ToString(), "(<PackageVersion>)([0-9\\.]+)(</PackageVersion>)", $"${{1}}{fullVersion}$3");
}
foreach (var file in GetFiles("**/AssemblyInfo.cs"))
{
Information($"Updating {file} to {fullVersion}...");
RegexReplaceInFile(file.ToString(), "(\\[assembly: AssemblyVersion\\(\")([0-9\\.]+)(\"\\)\\])", $"${{1}}{fullVersion}$3");
RegexReplaceInFile(file.ToString(), "(\\[assembly: AssemblyFileVersion\\(\")([0-9\\.]+)(\"\\)\\])", $"${{1}}{fullVersion}$3");
}
});
Task("Build-Project")
.Does(() => DotNetBuild("JAVS.TFTP", new DotNetBuildSettings
{
Configuration = config,
MSBuildSettings = new DotNetMSBuildSettings()
.TreatAllWarningsAs(MSBuildTreatAllWarningsAs.Error),
}));
Task("Run-Tests")
.IsDependentOn("Build-Project")
.Does(() => DotNetTest("JAVS.TFTP.UnitTests", new DotNetTestSettings
{
Configuration = config,
}));
Task("Default")
.IsDependentOn("Update-Version")
.IsDependentOn("Build-Project")
.IsDependentOn("Run-Tests");
RunTarget(target);
void RegexReplaceInFile(string filePath, string searchText, string replaceText)
{
var encoding = GetEncoding(filePath);
var oldContent = System.IO.File.ReadAllText(filePath, encoding);
var newContent = Regex.Replace(oldContent, searchText, replaceText);
System.IO.File.WriteAllText(filePath, newContent, encoding);
}
Encoding GetEncoding(string filePath)
{
var bom = new byte[4];
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
stream.Read(bom, 0, bom.Length);
}
#pragma warning disable CS0618
#pragma warning disable SYSLIB0001
if (bom[0] == 0x2b && bom[1] == 0x2f && bom[2] == 0x76) return Encoding.UTF7;
#pragma warning restore SYSLIB0001
#pragma warning restore CS0618
if (bom[0] == 0xef && bom[1] == 0xbb && bom[2] == 0xbf) return Encoding.UTF8;
if (bom[0] == 0xff && bom[1] == 0xfe) return Encoding.Unicode; //UTF-16LE
if (bom[0] == 0xfe && bom[1] == 0xff) return Encoding.BigEndianUnicode; //UTF-16BE
if (bom[0] == 0 && bom[1] == 0 && bom[2] == 0xfe && bom[3] == 0xff) return Encoding.UTF32;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
return Encoding.GetEncoding(1252);
}