private static void Main(string[] args) { string build; int buildInt; string fullVersion; string branch; ICommandLineOptions argsOptions = new CommandLineOptions(); try { CommandLine.Parse(args, ref argsOptions); } catch (ArgumentException) { argsOptions.DisplayOptions(); Environment.Exit(0); } CommandLineOptions options = argsOptions as CommandLineOptions; if (!options.IsOption(CommandLineOptions.Option.path)) { argsOptions.DisplayOptions(); Environment.Exit(0); } string directory = options.GetOption(CommandLineOptions.Option.path); if (options.IsOption(CommandLineOptions.Option.UpdateCopyright)) { string copyrightText = options.GetOption(CommandLineOptions.Option.UpdateCopyright); Console.WriteLine("Writing Copyright text: " + copyrightText); AssemblyUpdate copyrightUpdate = new AssemblyUpdate(copyrightText, AssemblyUpdate.UpdateMode.Copyright); copyrightUpdate.UpdateAll(directory); Environment.Exit(0); } if (options.IsOption(CommandLineOptions.Option.GetVersion)) { string templateName = options.GetOption(CommandLineOptions.Option.GetVersion); string template; if (string.IsNullOrEmpty(templateName)) { template = "{VER_BUILD}"; } else { if (!File.Exists(templateName)) { Console.WriteLine(string.Format("Version template '{0}' does not exist", templateName)); Environment.Exit(0); } using (var stream = new StreamReader(templateName)) { template = stream.ReadToEnd(); } } string gitDir = null; if (options.IsOption(CommandLineOptions.Option.git)) { gitDir = options.GetOption(CommandLineOptions.Option.git); } if (string.IsNullOrEmpty(gitDir)) { gitDir = directory; } VersionGIT git = new VersionGIT(); bool versionExists = git.ReadVersion(gitDir); if (File.Exists("version.txt")) { File.Delete("version.txt"); } if (!versionExists) { Console.WriteLine("Local GIT not up to date"); Environment.Exit(0); } build = git.GetBuild(); fullVersion = git.GetFullVersion(); branch = git.GetBranch(); var committish = git.GetCommittish(); TextWriter write = new StreamWriter("version.txt"); template = template .Replace("{GIT_VER_FULL}", fullVersion) .Replace("{GIT_VER_BUILD}", build) .Replace("{GIT_BRANCH}", git.IsReleaseBranch()? "" : branch) .Replace("{GIT_COMITTISH}", committish); write.Write(template); write.Close(); Int32.TryParse(build, out buildInt); Environment.Exit(buildInt); } if (options.IsOption(CommandLineOptions.Option.revert)) { build = "0"; fullVersion = ""; Console.WriteLine("Reverting to build 0"); } else { string gitDir = options.GetOption(CommandLineOptions.Option.git); if (string.IsNullOrEmpty(gitDir)) { gitDir = directory; } VersionGIT git = new VersionGIT(); bool versionExists = git.ReadVersion(gitDir); if (!versionExists) { Console.WriteLine("Local GIT not up to date"); Environment.Exit(0); } build = git.GetBuild(); fullVersion = git.GetFullVersion(); Console.WriteLine("GIT Version: " + fullVersion); } AssemblyUpdate update = new AssemblyUpdate(build, fullVersion); update.UpdateAll(directory); }
private static void Main(string[] args) { string build; int buildInt; string fullVersion; string branch; ICommandLineOptions argsOptions = new CommandLineOptions(); try { CommandLine.Parse(args, ref argsOptions); } catch (ArgumentException) { argsOptions.DisplayOptions(); Environment.Exit(0); } CommandLineOptions options = argsOptions as CommandLineOptions; if (!options.IsOption(CommandLineOptions.Option.path)) { argsOptions.DisplayOptions(); Environment.Exit(0); } string directory = options.GetOption(CommandLineOptions.Option.path); if (options.IsOption(CommandLineOptions.Option.UpdateCopyright)) { string copyrightText = options.GetOption(CommandLineOptions.Option.UpdateCopyright); Console.WriteLine("Writing Copyright text: " + copyrightText); AssemblyUpdate copyrightUpdate = new AssemblyUpdate(copyrightText, AssemblyUpdate.UpdateMode.Copyright); copyrightUpdate.UpdateAll(directory); Environment.Exit(0); } if (options.IsOption(CommandLineOptions.Option.GetVersion)) { string templateName = options.GetOption(CommandLineOptions.Option.GetVersion); string template; if (string.IsNullOrEmpty(templateName)) { template = "{VER_BUILD}"; } else { if (!File.Exists(templateName)) { Console.WriteLine(string.Format("Version template '{0}' does not exist", templateName)); Environment.Exit(0); } using (var stream = new StreamReader(templateName)) { template = stream.ReadToEnd(); } } string gitDir = null; if (options.IsOption(CommandLineOptions.Option.git)) { gitDir = options.GetOption(CommandLineOptions.Option.git); } if (string.IsNullOrEmpty(gitDir)) { gitDir = directory; } VersionGIT git = new VersionGIT(); bool versionExists = git.ReadVersion(gitDir); if (File.Exists("version.txt")) { File.Delete("version.txt"); } if (!versionExists) { Console.WriteLine("Local GIT not up to date"); Environment.Exit(0); } build = git.GetBuild(); fullVersion = git.GetFullVersion(); branch = git.GetBranch(); var committish = git.GetCommittish(); TextWriter write = new StreamWriter("version.txt"); template= template .Replace("{GIT_VER_FULL}", fullVersion) .Replace("{GIT_VER_BUILD}", build) .Replace("{GIT_BRANCH}", git.IsReleaseBranch()? "" : branch) .Replace("{GIT_COMITTISH}", committish); write.Write(template); write.Close(); Int32.TryParse(build, out buildInt); Environment.Exit(buildInt); } if (options.IsOption(CommandLineOptions.Option.revert)) { build = "0"; fullVersion = ""; Console.WriteLine("Reverting to build 0"); } else { string gitDir = options.GetOption(CommandLineOptions.Option.git); if (string.IsNullOrEmpty(gitDir)) { gitDir = directory; } VersionGIT git = new VersionGIT(); bool versionExists = git.ReadVersion(gitDir); if (!versionExists) { Console.WriteLine("Local GIT not up to date"); Environment.Exit(0); } build = git.GetBuild(); fullVersion = git.GetFullVersion(); Console.WriteLine("GIT Version: " + fullVersion); } AssemblyUpdate update = new AssemblyUpdate(build, fullVersion); update.UpdateAll(directory); }