/// <summary> /// Does the replace. /// </summary> /// <param name="inString">The input string.</param> /// <param name="gr">The GitResult.</param> /// <returns></returns> public static string DoReplace(string inString, GitResult gr) { var r = inString.Replace("$MajorVersion$", gr.MajorVersion.ToString(CultureInfo.InvariantCulture)); r = r.Replace("$MinorVersion$", gr.MinorVersion.ToString(CultureInfo.InvariantCulture)); r = r.Replace("$Revision$", gr.Revision.ToString(CultureInfo.InvariantCulture)); r = r.Replace("$Commit$", gr.Commit.ToString(CultureInfo.InvariantCulture)); r = r.Replace("$ShortHash$", gr.ShortHash); r = r.Replace("$LongHash$", gr.LongHash); r = r.Replace("$Branch$", gr.Branch); return r; }
/// <summary> /// Sets the environment variables. /// </summary> /// <param name="gitResult">The git result.</param> /// <exception cref="SecurityException">The caller does not have the required permission to perform this operation.</exception> public static void SetEnvironmentVariables(GitResult gitResult) { var fullVersionWithBranch = DoReplace("$Branch$:$MajorVersion$.$MinorVersion$.$Revision$-$Commit$-$ShortHash$", gitResult); var fullVersion = DoReplace("$MajorVersion$.$MinorVersion$.$Revision$-$Commit$-$ShortHash$", gitResult); var fullSemVer = DoReplace("$MajorVersion$.$MinorVersion$.$Revision$-$Branch$+$Commit$", gitResult) .Replace("-master", string.Empty); const EnvironmentVariableTarget target = EnvironmentVariableTarget.Process; Environment.SetEnvironmentVariable("GV-FullVersionWithBranch", fullVersionWithBranch, target); Environment.SetEnvironmentVariable("GV-FullVersion", fullVersion, target); Environment.SetEnvironmentVariable("GV-SemVer", fullSemVer, target); Environment.SetEnvironmentVariable("GV-Branch", gitResult.Branch, target); Environment.SetEnvironmentVariable("GV-MajorVersion", gitResult.MajorVersion.ToString(), target); Environment.SetEnvironmentVariable("GV-MinorVersion", gitResult.MinorVersion.ToString(), target); Environment.SetEnvironmentVariable("GV-Revision", gitResult.Revision.ToString(), target); Environment.SetEnvironmentVariable("GV-Commit", gitResult.Commit.ToString(), target); Environment.SetEnvironmentVariable("GV-ShortHash", gitResult.ShortHash, target); Environment.SetEnvironmentVariable("GV-LongHash", gitResult.LongHash, target); }
/// <summary> /// Converts git results to string /// </summary> /// <param name="gr">GitResult.</param> /// <returns></returns> public static string GitResultToString(GitResult gr) { var s = gr.MajorVersion + "."; s += gr.MinorVersion + "."; s += gr.Revision + "-"; s += gr.Commit + "-"; s += gr.ShortHash; return s; }