forked from sbozzie/test-intel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
86 lines (80 loc) · 3.36 KB
/
Copy pathProgram.cs
File metadata and controls
86 lines (80 loc) · 3.36 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
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
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
namespace PostBuild {
internal class Program {
/// <summary>
/// Used to locate and parse the string holding the product
/// version in ProductInfo.cs.
/// </summary>
private static readonly Regex VersionMatch
= new Regex("^(.*\\sProductVersion\\s.*\\.)(\\d+)(\".*)$");
/// <summary>
/// Program Entry Point
/// </summary>
static int Main(string[] args) {
Console.WriteLine("PostBuild - Version string management");
if (args.Length != 4) {
Console.WriteLine("Usage: PostBuild <executable> <productinfo.cs> <updates.xml> <update-uri>");
return 1;
}
// Extract the desired information from the assembly
Console.WriteLine("Loading Executable \"{0}\".", args[0]);
var assembly = Assembly.LoadFrom(args[0]);
var assemblyName = assembly.GetName();
var assemblyVersion = assembly
.GetCustomAttributes(
typeof(AssemblyFileVersionAttribute),
true)
.Cast<AssemblyFileVersionAttribute>()
.Single();
Console.WriteLine("{0}, FileVersion={1}",
assemblyName,
assemblyVersion.Version);
// Generate the updates.xml file
if (!String.IsNullOrEmpty(args[2])) {
var xmlSettings = new XmlWriterSettings() {
Indent = true
};
Console.WriteLine("Writing version list to \"{0}\"", args[2]);
using (var xmlWriter = XmlWriter.Create(args[2], xmlSettings)) {
xmlWriter.WriteStartElement("assembly-list");
xmlWriter.WriteStartElement("assembly");
xmlWriter.WriteAttributeString("name", assemblyName.Name);
xmlWriter.WriteAttributeString("version", assemblyVersion.Version);
xmlWriter.WriteAttributeString("update-uri", args[3]);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.Flush();
}
}
// Update version number in file
if (!String.IsNullOrEmpty(args[1])) {
Console.WriteLine("Incrementing version string in \"{0}\"", args[1]);
var text = File.ReadAllLines(args[1]);
for (int n = 0; n < text.Length; ++n) {
var match = VersionMatch.Match(text[n]);
if (match.Success) {
var newVersion = Int16.Parse(match.Groups[2].Value) + 1;
text[n] = String.Format(
CultureInfo.InvariantCulture,
"{0}{1}{2}",
match.Groups[1].Value,
newVersion,
match.Groups[3].Value);
}
}
File.WriteAllLines(args[1], text);
}
// Success
Console.WriteLine("Done");
return 0;
}
}
}