1 |
using System; |
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Reflection; |
6 |
using System.IO; |
7 |
|
8 |
namespace VersionWriter |
9 |
{ |
10 |
class Program |
11 |
{ |
12 |
static void Main(string[] args) |
13 |
{ |
14 |
if (args.Length == 0 || args.Length > 2) |
15 |
{ |
16 |
Console.WriteLine("USAGE: VersionWriter.exe assemblypath [ouptutfile]"); |
17 |
return; |
18 |
} |
19 |
// args[0] = path to assembly |
20 |
// args[1] = output file |
21 |
|
22 |
string asm_path = ""; |
23 |
string out_file = ""; |
24 |
if (args.Length == 1) |
25 |
{ |
26 |
asm_path = args[0]; |
27 |
out_file = string.Format("{0}-Version.txt", asm_path); |
28 |
} |
29 |
else |
30 |
{ |
31 |
asm_path = args[0]; |
32 |
out_file = args[1]; |
33 |
} |
34 |
|
35 |
Console.WriteLine("Input: {0}", asm_path); |
36 |
Console.WriteLine("Output: {0}", out_file); |
37 |
|
38 |
Assembly asm = Assembly.LoadFile(asm_path); |
39 |
|
40 |
string version = asm.GetName().Version.ToString(); |
41 |
|
42 |
Console.WriteLine("Writing version: {0} to {1}", version, out_file); |
43 |
using(FileStream fs = new FileStream(out_file, FileMode.Create, FileAccess.Write, FileShare.Read)) |
44 |
{ |
45 |
StreamWriter sw = new StreamWriter(fs); |
46 |
sw.AutoFlush = true; |
47 |
sw.Write(version); |
48 |
sw.Close(); |
49 |
} |
50 |
Console.WriteLine("Wrote version: {0} to {1}", version, out_file); |
51 |
} |
52 |
} |
53 |
} |