Esempio n. 1
0
        private static void GetRepositoryVersions(out VersionInfo currentRepositoryVersion, out VersionInfo latestRepositoryVersion)
        {
            var workingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly()?.Location);
            var clrHash          = new CommandLineRunner();
            var clrTags          = new CommandLineRunner();
            var gitPath          = GetGitPath();

            if (clrHash.RunCommandAndGetOutput(gitPath, "rev-parse --verify HEAD", workingDirectory) && clrTags.RunCommandAndGetOutput(gitPath, "describe --long --tags", workingDirectory))
            {
                if (!LongGitTagRegex.IsMatch(clrTags.Result) && !ShortGitTagRegex.IsMatch(clrTags.Result))
                {
                    throw new FormatException($"Invalid Git version tag: '{clrTags.Result}' (major.minor.maintenance-build expected)");
                }
                currentRepositoryVersion = new VersionInfo(clrTags.Result, clrHash.Result);
            }
            else
            {
                currentRepositoryVersion = new VersionInfo(); // no git repository
            }
            if (clrHash.RunCommandAndGetOutput(gitPath, "rev-parse --verify refs/heads/master", workingDirectory) && clrTags.RunCommandAndGetOutput(gitPath, "describe --long --tags refs/heads/master", workingDirectory))
            {
                if (!LongGitTagRegex.IsMatch(clrTags.Result) && !ShortGitTagRegex.IsMatch(clrTags.Result))
                {
                    throw new FormatException("Invalid Git version tag: '{clrTags.Result}' (major.minor.maintenance-build expected)");
                }
                latestRepositoryVersion = new VersionInfo(clrTags.Result, clrHash.Result);
            }
            else
            {
                latestRepositoryVersion = new VersionInfo(); // no git repository
            }
        }
Esempio n. 2
0
        static int Main(string[] args)
        {
            string errorFileName = System.Reflection.Assembly.GetEntryAssembly().Location.Replace(".exe", "_error.txt");

            if (args.Length != 2)
            {
                Console.WriteLine("UpdateAssemblyDescription 0.9");
                Console.WriteLine("UpdateAssemblyDescription <template with [GITHASH]> <target file>");
                File.WriteAllText(errorFileName, "Wrong number of arguments: " + args.Length);
                return(1);
            }

            string workingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            string template      = args[0];
            string target        = args[1];

            var clrHash   = new CommandLineRunner();
            var rcGitHash = clrHash.RunCommandAndGetOutput(GetGitPath(), "rev-parse --verify HEAD", workingFolder);
            var clrTags   = new CommandLineRunner();

            if (rcGitHash && clrTags.RunCommandAndGetOutput(GetGitPath(), "describe --tags", workingFolder))
            {
                try
                {
                    DoUpdateAssembly("[GITHASH]", clrHash.Result, template, target);
                    if (!clrTags.Result.Contains("-"))
                    {
                        clrTags.Result += "-0";
                    }
                    DoUpdateAssembly("[REVNO]", clrTags.Result.Split('-')[1], target, target);
                    return(0);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    File.WriteAllText(errorFileName, e.Message);
                }
            }
            else
            {
                try
                {
                    // allow for compile without git
                    DoUpdateAssembly("[GITHASH]", string.Empty, template, target);
                    DoUpdateAssembly("[REVNO]", "0", target, target);
                }
                catch
                {
                }

                Console.WriteLine("Error running Git");
                Console.WriteLine(" - git folder: " + workingFolder);
                Console.WriteLine(" - template: " + template);
                Console.WriteLine(" - target: " + target);
                File.WriteAllText(errorFileName, " - git folder: " + workingFolder + Environment.NewLine +
                                  " - template: " + template + Environment.NewLine +
                                  " - target: " + target);
            }
            return(1);
        }
Esempio n. 3
0
        private static VersionInfo GetNewVersion()
        {
            var version = new VersionInfo {
                Version = "1.0.0", RevisionGuid = "0", BuildNumber = "9999"
            };
            var workingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            var clrHash       = new CommandLineRunner();
            var clrTags       = new CommandLineRunner();
            var gitPath       = GetGitPath();

            if (clrHash.RunCommandAndGetOutput(gitPath, "rev-parse --verify HEAD", workingFolder) && clrTags.RunCommandAndGetOutput(gitPath, "describe --tags", workingFolder))
            {
                if (!VersionNumberRegex.IsMatch(clrTags.Result))
                {
                    throw new Exception("Error: Invalid Git version tag (should number.number.number): '" + clrTags.Result + "'");
                }

                version.RevisionGuid = clrHash.Result;

                version.Version = clrTags.Result.Substring(0, clrTags.Result.LastIndexOf('-'));
                version.Version = version.Version.Replace("-", ".");

                version.BuildNumber = version.Version.Remove(0, version.Version.LastIndexOf('.')).Trim('.');
            }
            if (version.RevisionGuid == "0" && version.BuildNumber == "9999")
            {
                Console.WriteLine("WARNING: Could not run Git - build number will be 9999!");
            }
            return(version);
        }
Esempio n. 4
0
        static int Main(string[] args)
        {
            string errorFileName = System.Reflection.Assembly.GetEntryAssembly().Location.Replace(".exe", "_error.txt");

            if (args.Length != 2)
            {
                Console.WriteLine("UpdateAssemblyDescription 0.9");
                Console.WriteLine("UpdateAssemblyDescription <template with [GITHASH]> <target file>");
                File.WriteAllText(errorFileName, "Wrong number of arguments: " + args.Length);
                return 1;
            }

            Console.WriteLine("Updating assembly info...");
            string workingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            string template = args[0];
            string target = args[1];

            var clrHash = new CommandLineRunner();
            var rcGitHash = clrHash.RunCommandAndGetOutput(GetGitPath(), "rev-parse --verify HEAD", workingFolder);
            var clrTags = new CommandLineRunner();
            if (rcGitHash && clrTags.RunCommandAndGetOutput(GetGitPath(), "describe --tags", workingFolder))
            {
                try
                {
                    DoUpdateAssembly("[GITHASH]", clrHash.Result, template, target);
                    if (!clrTags.Result.Contains("-"))
                        clrTags.Result += "-0";
                    DoUpdateAssembly("[REVNO]", clrTags.Result.Split('-')[1] , target, target);
                    return 0;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    File.WriteAllText(errorFileName, e.Message);
                }
            }
            else
            {
                try
                {
                    // allow for compile without git
                    DoUpdateAssembly("[GITHASH]", string.Empty, template, target);
                    DoUpdateAssembly("[REVNO]", "0", target, target);
                }
                catch
                {
                }

                Console.WriteLine("Error running Git");
                Console.WriteLine(" - git folder: " + workingFolder);
                Console.WriteLine(" - template: " + template);
                Console.WriteLine(" - target: " + target);
                File.WriteAllText(errorFileName, " - git folder: " + workingFolder + Environment.NewLine +
                                                 " - template: " + template + Environment.NewLine +
                                                 " - target: " + target);
            }
            return 1;
        }
Esempio n. 5
0
        private static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("UpdateAssemblyInfo 1.0");
                Console.WriteLine("UpdateAssemblyInfo <template with [GITHASH]> <target file>");
                Console.WriteLine("Wrong number of arguments: " + args.Length);
                return(1);
            }

            Console.WriteLine("Updating assembly info...");
            string workingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            string template      = args[0];
            string target        = args[1];

            var clrHash   = new CommandLineRunner();
            var rcGitHash = clrHash.RunCommandAndGetOutput(GetGitPath(), "rev-parse --verify HEAD", workingFolder);
            var clrTags   = new CommandLineRunner();

            if (rcGitHash && clrTags.RunCommandAndGetOutput(GetGitPath(), "describe --tags", workingFolder))
            {
                try
                {
                    DoUpdateAssembly("[GITHASH]", clrHash.Result, template, target);
                    if (!clrTags.Result.Contains("-"))
                    {
                        clrTags.Result += "-0";
                    }
                    DoUpdateAssembly("[REVNO]", clrTags.Result.Split('-')[1], target, target);
                    return(0);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
            }
            else
            {
                try
                {
                    // allow to compile without git
                    Console.WriteLine("Warning: Could not run Git - build number will be 9999!");
                    DoUpdateAssembly("[GITHASH]", string.Empty, template, target);
                    DoUpdateAssembly("[REVNO]", "9999", target, target);
                    return(0);
                }
                catch
                {
                    Console.WriteLine("Error running Git");
                    Console.WriteLine(" - Git folder: " + workingFolder);
                    Console.WriteLine(" - Template: " + template);
                    Console.WriteLine(" - Target: " + target);
                }
            }
            return(1);
        }
Esempio n. 6
0
        private static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("UpdateAssemblyInfo 1.0");
                Console.WriteLine("UpdateAssemblyInfo <template with [GITHASH]> <target file>");
                Console.WriteLine("Wrong number of arguments: " + args.Length);
                return 1;
            }

            Console.WriteLine("Updating assembly info...");
            string workingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            string template = args[0];
            string target = args[1];

            var clrHash = new CommandLineRunner();
            var rcGitHash = clrHash.RunCommandAndGetOutput(GetGitPath(), "rev-parse --verify HEAD", workingFolder);
            var clrTags = new CommandLineRunner();
            if (rcGitHash && clrTags.RunCommandAndGetOutput(GetGitPath(), "describe --tags", workingFolder))
            {
                try
                {
                    DoUpdateAssembly("[GITHASH]", clrHash.Result, template, target);
                    if (!clrTags.Result.Contains("-"))
                        clrTags.Result += "-0";
                    DoUpdateAssembly("[REVNO]", clrTags.Result.Split('-')[1], target, target);
                    return 0;
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
            }
            else
            {
                try
                {
                    // allow to compile without git
                    Console.WriteLine("Warning: Could not run Git - build number will be 9999!");
                    DoUpdateAssembly("[GITHASH]", string.Empty, template, target);
                    DoUpdateAssembly("[REVNO]", "9999", target, target);
                    return 0;
                }
                catch
                {
                    Console.WriteLine("Error running Git");
                    Console.WriteLine(" - Git folder: " + workingFolder);
                    Console.WriteLine(" - Template: " + template);
                    Console.WriteLine(" - Target: " + target);
                }
            }
            return 1;
        }
Esempio n. 7
0
        private static VersionInfo GetNewVersion()
        {
            var versionInfo = new VersionInfo {
                Version = DefaultVersion, RevisionGuid = "0"
            };
            var workingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            var clrHash       = new CommandLineRunner();
            var clrTags       = new CommandLineRunner();
            var gitPath       = GetGitPath();

            if (clrHash.RunCommandAndGetOutput(gitPath, "rev-parse --verify HEAD", workingFolder) && clrTags.RunCommandAndGetOutput(gitPath, "describe --tags", workingFolder))
            {
                if (!VersionNumberRegex.IsMatch(clrTags.Result))
                {
                    throw new Exception("Error: Invalid Git version tag (should number.number.number): '" + clrTags.Result + "'");
                }
                versionInfo.RevisionGuid = clrHash.Result;
                versionInfo.Version      = clrTags.Result.Substring(0, clrTags.Result.LastIndexOf('-'));
                versionInfo.Version      = versionInfo.Version.Replace("-", ".");
            }
            return(versionInfo);
        }
Esempio n. 8
0
        private static VersionInfo GetNewVersion()
        {
            var version = new VersionInfo { Version = "1.0.0", RevisionGuid = "0", BuildNumber = "9999" };
            var workingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            var clrHash = new CommandLineRunner();
            var clrTags = new CommandLineRunner();
            var gitPath = GetGitPath();
            if (clrHash.RunCommandAndGetOutput(gitPath, "rev-parse --verify HEAD", workingFolder) && clrTags.RunCommandAndGetOutput(gitPath, "describe --tags", workingFolder))
            {
                if (!VersionNumberRegex.IsMatch(clrTags.Result))
                {
                    throw new Exception("Error: Invalid Git version tag (should number.number.number): '" + clrTags.Result + "'");
                }

                version.RevisionGuid = clrHash.Result;

                version.Version = clrTags.Result.Substring(0, clrTags.Result.LastIndexOf('-'));
                version.Version = version.Version.Replace("-", ".");

                version.BuildNumber = version.Version.Remove(0, version.Version.LastIndexOf('.')).Trim('.');
            }
            if (version.RevisionGuid == "0" && version.BuildNumber == "9999")
            {
                Console.WriteLine("WARNING: Could not run Git - build number will be 9999!");
            }
            return version;
        }
Esempio n. 9
0
        private static int Main(string[] args)
        {
            var myName = Environment.GetCommandLineArgs()[0];
            myName = Path.GetFileNameWithoutExtension(string.IsNullOrWhiteSpace(myName)
                   ? System.Reflection.Assembly.GetEntryAssembly().Location
                   : myName);

            if (args.Length != 2)
            {
                Console.Write("Usage: " + myName + @" <template> <target>
              <template> Path to the template file with [GITHASH] and [REVNO]
              <target>   Path to the target file (AssemblyInfo.cs)
            ");
                return 1;
            }

            Console.WriteLine("Updating assembly info...");
            var workingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            var templateFile = args[0];
            var targetFile = args[1];
            var template = new Template(templateFile);

            var clrHash = new CommandLineRunner();
            var clrTags = new CommandLineRunner();
            var gitPath = GetGitPath();
            string exceptionMessage;
            if (clrHash.RunCommandAndGetOutput(gitPath, "rev-parse --verify HEAD", workingFolder) &&
                clrTags.RunCommandAndGetOutput(gitPath, "describe --tags", workingFolder))
            {
                try
                {
                    template.Replace("[GITHASH]", clrHash.Result);
                    if (clrTags.Result.IndexOf('-') < 0)
                        clrTags.Result += "-0";
                    template.Replace("[REVNO]", clrTags.Result.Split('-')[1]);
                    template.Save(targetFile);
                    return 0;
                }
                catch (Exception ex)
                {
                    exceptionMessage = ex.Message;
                }
            }
            else
            {
                try
                {
                    // allow to compile without git
                    Console.WriteLine("WARNING: Could not run Git - build number will be 9999!");
                    template.Replace("[GITHASH]", string.Empty);
                    template.Replace("[REVNO]", "9999");
                    template.Save(targetFile);
                    return 0;
                }
                catch (Exception ex)
                {
                    exceptionMessage = ex.Message;
                }
            }
            Console.WriteLine(myName + ": Could not update AssemblyInfo: " + exceptionMessage);
            Console.WriteLine(" - Git folder: " + workingFolder);
            Console.WriteLine(" - Template: " + templateFile);
            Console.WriteLine(" - Target: " + targetFile);
            return 1;
        }
Esempio n. 10
0
 private static VersionInfo GetNewVersion()
 {
     var versionInfo = new VersionInfo { Version = DefaultVersion, RevisionGuid = "0" };
     var workingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
     var clrHash = new CommandLineRunner();
     var clrTags = new CommandLineRunner();
     var gitPath = GetGitPath();
     if (clrHash.RunCommandAndGetOutput(gitPath, "rev-parse --verify HEAD", workingFolder) && clrTags.RunCommandAndGetOutput(gitPath, "describe --tags", workingFolder))
     {
         if (!VersionNumberRegex.IsMatch(clrTags.Result))
         {
             throw new Exception("Error: Invalid Git version tag (should number.number.number): '" + clrTags.Result + "'");
         }
         versionInfo.RevisionGuid = clrHash.Result;
         versionInfo.Version = clrTags.Result.Substring(0, clrTags.Result.LastIndexOf('-'));
         versionInfo.Version = versionInfo.Version.Replace("-", ".");
     }
     return versionInfo;
 }
Esempio n. 11
0
        private static int Main(string[] args)
        {
            var myName = Environment.GetCommandLineArgs()[0];

            myName = Path.GetFileNameWithoutExtension(string.IsNullOrWhiteSpace(myName)
                   ? System.Reflection.Assembly.GetEntryAssembly().Location
                   : myName);

            if (args.Length != 2)
            {
                Console.Write("Usage: " + myName + @" <template> <target>
  <template> Path to the template file with [GITHASH] and [REVNO]
  <target>   Path to the target file (AssemblyInfo.cs)
");
                return(1);
            }

            Console.WriteLine("Updating assembly info...");
            var workingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            var templateFile  = args[0];
            var targetFile    = args[1];
            var template      = new Template(templateFile);

            var    clrHash = new CommandLineRunner();
            var    clrTags = new CommandLineRunner();
            var    gitPath = GetGitPath();
            string exceptionMessage;

            if (clrHash.RunCommandAndGetOutput(gitPath, "rev-parse --verify HEAD", workingFolder) &&
                clrTags.RunCommandAndGetOutput(gitPath, "describe --tags", workingFolder))
            {
                try
                {
                    template.Replace("[GITHASH]", clrHash.Result);
                    if (clrTags.Result.IndexOf('-') < 0)
                    {
                        clrTags.Result += "-0";
                    }
                    template.Replace("[REVNO]", clrTags.Result.Split('-')[1]);
                    template.Save(targetFile);
                    return(0);
                }
                catch (Exception ex)
                {
                    exceptionMessage = ex.Message;
                }
            }
            else
            {
                try
                {
                    // allow to compile without git
                    Console.WriteLine("WARNING: Could not run Git - build number will be 9999!");
                    template.Replace("[GITHASH]", string.Empty);
                    template.Replace("[REVNO]", "9999");
                    template.Save(targetFile);
                    return(0);
                }
                catch (Exception ex)
                {
                    exceptionMessage = ex.Message;
                }
            }
            Console.WriteLine(myName + ": Could not update AssemblyInfo: " + exceptionMessage);
            Console.WriteLine(" - Git folder: " + workingFolder);
            Console.WriteLine(" - Template: " + templateFile);
            Console.WriteLine(" - Target: " + targetFile);
            return(1);
        }