forked from Mapsui/Mapsui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (45 loc) · 2.1 KB
/
Program.cs
File metadata and controls
50 lines (45 loc) · 2.1 KB
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace VersionUpdater
{
static class Program
{
static void Main()
{
var arguments = VersionUpdaterArguments.Parse();
Console.WriteLine($"{nameof(arguments.Major)} {arguments.Major}");
Console.WriteLine($"{nameof(arguments.Minor)} {arguments.Minor}");
Console.WriteLine($"{nameof(arguments.Patch)} {arguments.Patch}");
Console.WriteLine($"{nameof(arguments.Prerelease)} {arguments.Prerelease}");
var files = GetFiles().ToList();
UpdateFiles(arguments, files);
}
public static IEnumerable<string> GetFiles()
{
foreach (string file in Directory.EnumerateFiles(
Environment.CurrentDirectory, "AssemblyInfo.cs", SearchOption.AllDirectories))
{
yield return file;
}
}
public static void UpdateFiles(VersionUpdaterArguments arguments, IEnumerable<string> files)
{
foreach (var file in files)
{
var text = File.ReadAllText(file);
var assemblyVersionRegex = new Regex("AssemblyVersion[(](.*?)?[)]");
text = assemblyVersionRegex.Replace(text, $"AssemblyVersion(\"{arguments.Major}.{arguments.Minor}.{arguments.Patch}\")");
var assemblyFileVersionRegex = new Regex("AssemblyFileVersion[(](.*?)?[)]");
text = assemblyFileVersionRegex.Replace(text, $"AssemblyFileVersion(\"{arguments.Major}.{arguments.Minor}.{arguments.Patch}\")");
var assemblyInformationalVersionRegex = new Regex("AssemblyInformationalVersion[(](.*?)?[)]");
text = assemblyInformationalVersionRegex.Replace(text, $"AssemblyInformationalVersion(\"{arguments.Major}.{arguments.Minor}.{arguments.Patch}{arguments.Prerelease}\")");
Encoding utf8WithBom = new UTF8Encoding(true);
File.WriteAllText(file, text, utf8WithBom);
}
}
}
}