using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.IO; namespace VersionWriter { class Program { static void Main(string[] args) { if (args.Length == 0 || args.Length > 2) { Console.WriteLine("USAGE: VersionWriter.exe assemblypath [ouptutfile]"); return; } // args[0] = path to assembly // args[1] = output file string asm_path = ""; string out_file = ""; if (args.Length == 1) { asm_path = args[0]; out_file = string.Format("{0}-Version.txt", asm_path); } else { asm_path = args[0]; out_file = args[1]; } Console.WriteLine("Input: {0}", asm_path); Console.WriteLine("Output: {0}", out_file); Assembly asm = Assembly.LoadFile(asm_path); string version = asm.GetName().Version.ToString(); Console.WriteLine("Writing version: {0} to {1}", version, out_file); using(FileStream fs = new FileStream(out_file, FileMode.Create, FileAccess.Write, FileShare.Read)) { StreamWriter sw = new StreamWriter(fs); sw.AutoFlush = true; sw.Write(version); sw.Close(); } Console.WriteLine("Wrote version: {0} to {1}", version, out_file); } } }