Try to allow for RC

This commit is contained in:
niksedk 2023-05-11 16:29:11 +02:00
parent 879eb44c66
commit 26f7f38787
2 changed files with 39 additions and 1 deletions

View File

@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Collections.Generic;
using System.Diagnostics;
namespace UpdateAssemblyInfo
{
@ -6,8 +7,18 @@ namespace UpdateAssemblyInfo
{
public string Result { get; set; }
private static readonly Dictionary<string, string> CommandLineResultCache = new Dictionary<string, string>();
public bool RunCommandAndGetOutput(string command, string arguments, string workingFolder)
{
var cacheKey = command + " " + arguments;
if (CommandLineResultCache.TryGetValue(cacheKey, out var result))
{
Result = result;
return true;
}
var p = new Process
{
StartInfo =
@ -33,6 +44,11 @@ namespace UpdateAssemblyInfo
p.BeginOutputReadLine(); // Async reading of output to prevent deadlock
if (p.WaitForExit(5000))
{
if (CommandLineResultCache.ContainsKey(command))
{
CommandLineResultCache.Add(cacheKey, Result);
}
return p.ExitCode == 0;
}
return false;

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
@ -313,9 +314,30 @@ namespace UpdateAssemblyInfo
Console.Write(WorkInProgress);
}
private static bool IsRCVersion()
{
var workingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly()?.Location);
var clrTags = new CommandLineRunner();
var gitPath = GetGitPath();
if (clrTags.RunCommandAndGetOutput(gitPath, "describe --long --tags", workingDirectory))
{
if (clrTags.Result.Contains("RC"))
{
return true;
}
}
return false;
}
//debug: "..\..\ui\Properties\AssemblyInfo.cs.template" "..\..\src\libse\Properties\AssemblyInfo.cs.template"
private static int Main(string[] args)
{
if (IsRCVersion())
{
return 0;
}
var myName = Environment.GetCommandLineArgs()[0];
myName = Path.GetFileNameWithoutExtension(string.IsNullOrWhiteSpace(myName) ? System.Reflection.Assembly.GetEntryAssembly()?.Location : myName);