Minor fix for Release vs Debug when generating language files / updating version number

This commit is contained in:
niksedk 2015-08-29 08:46:26 +02:00
parent 93f2a36fc1
commit cf912db084
3 changed files with 72 additions and 73 deletions

View File

@ -1,12 +1,11 @@
@ECHO OFF @ECHO OFF
SETLOCAL SETLOCAL
PUSHD %~dp0 PUSHD %~dp0
SET "ConfigurationName=%~2"
IF /I "%~1" == "lang" GOTO UpdateLanguageFiles IF /I "%~1" == "lang" GOTO UpdateLanguageFiles
IF /I "%~1" == "rev" GOTO UpdateAssemblyInfo IF /I "%~1" == "rev" GOTO UpdateAssemblyInfo
:END :END
POPD POPD
ENDLOCAL ENDLOCAL
@ -14,16 +13,12 @@ EXIT /B
:UpdateLanguageFiles :UpdateLanguageFiles
IF NOT EXIST "src\UpdateLanguageFiles\bin\Release\UpdateLanguageFiles.exe" IF NOT EXIST "src\UpdateLanguageFiles\bin\Debug\UpdateLanguageFiles.exe" ( IF NOT EXIST "src\UpdateLanguageFiles\bin\%ConfigurationName%\UpdateLanguageFiles.exe" (
ECHO Compile Subtitle Edit first! ECHO Compile Subtitle Edit first!
GOTO END GOTO END
) )
IF EXIST "src\UpdateLanguageFiles\bin\Release\UpdateLanguageFiles.exe" ( "src\UpdateLanguageFiles\bin\%ConfigurationName%\UpdateLanguageFiles.exe" "LanguageMaster.xml" "src\Logic\LanguageDeserializer.cs"
"src\UpdateLanguageFiles\bin\Release\UpdateLanguageFiles.exe" "LanguageMaster.xml" "src\Logic\LanguageDeserializer.cs"
) ELSE (
"src\UpdateLanguageFiles\bin\Debug\UpdateLanguageFiles.exe" "LanguageMaster.xml" "src\Logic\LanguageDeserializer.cs"
)
IF %ERRORLEVEL% NEQ 0 ( IF %ERRORLEVEL% NEQ 0 (
ECHO ERROR: Something went wrong when generating the language files... ECHO ERROR: Something went wrong when generating the language files...
@ -32,16 +27,12 @@ GOTO END
:UpdateAssemblyInfo :UpdateAssemblyInfo
IF NOT EXIST "src\UpdateAssemblyInfo\bin\Release\UpdateAssemblyInfo.exe" IF NOT EXIST "src\UpdateAssemblyInfo\bin\Debug\UpdateAssemblyInfo.exe" ( IF NOT EXIST "src\UpdateAssemblyInfo\bin\%ConfigurationName%\UpdateAssemblyInfo.exe" (
ECHO Compile Subtitle Edit first! ECHO Compile Subtitle Edit first!
GOTO END GOTO END
) )
IF EXIST "src\UpdateAssemblyInfo\bin\Release\UpdateAssemblyInfo.exe" ( "src\UpdateAssemblyInfo\bin\%ConfigurationName%\UpdateAssemblyInfo.exe" "src\Properties\AssemblyInfo.cs.template" "libse\Properties\AssemblyInfo.cs.template"
"src\UpdateAssemblyInfo\bin\Release\UpdateAssemblyInfo.exe" "src\Properties\AssemblyInfo.cs.template" "libse\Properties\AssemblyInfo.cs.template"
) ELSE (
"src\UpdateAssemblyInfo\bin\Debug\UpdateAssemblyInfo.exe" "src\Properties\AssemblyInfo.cs.template" "libse\Properties\AssemblyInfo.cs.template"
)
IF %ERRORLEVEL% NEQ 0 ( IF %ERRORLEVEL% NEQ 0 (
ECHO ERROR: Something went wrong when generating the revision number... ECHO ERROR: Something went wrong when generating the revision number...

View File

@ -1600,7 +1600,7 @@
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PreBuildEvent>"$(ProjectDir)..\build_helpers.bat" rev &amp;&amp; "$(ProjectDir)..\build_helpers.bat" lang</PreBuildEvent> <PreBuildEvent>"$(ProjectDir)..\build_helpers.bat" rev $(ConfigurationName) &amp;&amp; "$(ProjectDir)..\build_helpers.bat" lang $(ConfigurationName)</PreBuildEvent>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>COPY /Y /V "$(ProjectDir)packages\NHunspell.1.2.5554.16953\content\*.dll" "$(TargetDir)" <PostBuildEvent>COPY /Y /V "$(ProjectDir)packages\NHunspell.1.2.5554.16953\content\*.dll" "$(TargetDir)"

View File

@ -12,10 +12,11 @@ namespace UpdateAssemblyInfo
{ {
public string Version { get; set; } public string Version { get; set; }
public string RevisionGuid { get; set; } public string RevisionGuid { get; set; }
public string BuildNumber { get; set; }
} }
private static void UpdateAssemblyInfo(string templateFileName, VersionInfo versionInfo) private const string DefaultVersion = "1.0.0.0";
private static void UpdateAssemblyInfo(string templateFileName, VersionInfo newVersionInfo)
{ {
var lines = File.ReadAllLines(templateFileName); var lines = File.ReadAllLines(templateFileName);
var sb = new StringBuilder(); var sb = new StringBuilder();
@ -23,6 +24,8 @@ namespace UpdateAssemblyInfo
foreach (var line in lines) foreach (var line in lines)
{ {
var original = line; var original = line;
if (newVersionInfo.Version != DefaultVersion)
{ // only replace version info if Git is installed
var l = line.Trim(); var l = line.Trim();
while (l.Contains(" ")) while (l.Contains(" "))
{ {
@ -39,10 +42,10 @@ namespace UpdateAssemblyInfo
{ {
begin++; begin++;
string oldVersion = original.Substring(begin, end - begin); string oldVersion = original.Substring(begin, end - begin);
if (oldVersion != versionInfo.Version) if (oldVersion != newVersionInfo.Version)
{ {
change = true; change = true;
original = original.Substring(0, begin) + versionInfo.Version + original.Remove(0, end); original = original.Substring(0, begin) + newVersionInfo.Version + original.Remove(0, end);
} }
} }
} }
@ -55,10 +58,11 @@ namespace UpdateAssemblyInfo
{ {
begin++; begin++;
string oldRevisionGuid = original.Substring(begin, end - begin); string oldRevisionGuid = original.Substring(begin, end - begin);
if (oldRevisionGuid != versionInfo.RevisionGuid) if (oldRevisionGuid != newVersionInfo.RevisionGuid)
{ {
change = true; change = true;
original = original.Substring(0, begin) + versionInfo.RevisionGuid + original.Remove(0, end); original = original.Substring(0, begin) + newVersionInfo.RevisionGuid + original.Remove(0, end);
}
} }
} }
} }
@ -72,7 +76,7 @@ namespace UpdateAssemblyInfo
private static VersionInfo GetOldVersionNumber(string subtitleEditTemplateFileName) private static VersionInfo GetOldVersionNumber(string subtitleEditTemplateFileName)
{ {
var version = new VersionInfo { Version = "1.0.0.0", RevisionGuid = "0", BuildNumber = "0" }; var versionInfo = new VersionInfo { Version = DefaultVersion, RevisionGuid = "0" };
var oldFileName = subtitleEditTemplateFileName.Replace(".template", string.Empty); var oldFileName = subtitleEditTemplateFileName.Replace(".template", string.Empty);
if (File.Exists(oldFileName)) if (File.Exists(oldFileName))
{ {
@ -94,8 +98,7 @@ namespace UpdateAssemblyInfo
if (end > begin && begin > 0) if (end > begin && begin > 0)
{ {
begin++; begin++;
version.Version = l.Substring(begin, end - begin); versionInfo.Version = l.Substring(begin, end - begin);
version.BuildNumber = version.Version.Substring(version.Version.LastIndexOf('.') + 1);
} }
} }
else if (l.StartsWith("[assembly: AssemblyDescription", StringComparison.Ordinal) || else if (l.StartsWith("[assembly: AssemblyDescription", StringComparison.Ordinal) ||
@ -106,20 +109,20 @@ namespace UpdateAssemblyInfo
if (end > begin && begin > 0) if (end > begin && begin > 0)
{ {
begin++; begin++;
version.RevisionGuid = l.Substring(begin, end - begin); versionInfo.RevisionGuid = l.Substring(begin, end - begin);
} }
} }
} }
} }
return version; return versionInfo;
} }
// 3.4.8-226-g7037fef // e.g.: 3.4.8-226-g7037fef
private static readonly Regex VersionNumberRegex = new Regex(@"^\d+\.\d+\.\d+\-.+$", RegexOptions.Compiled); private static readonly Regex VersionNumberRegex = new Regex(@"^\d+\.\d+\.\d+\-.+$", RegexOptions.Compiled);
private static VersionInfo GetNewVersion() private static VersionInfo GetNewVersion()
{ {
var version = new VersionInfo { Version = "1.0.0", RevisionGuid = "0", BuildNumber = "9999" }; var versionInfo = new VersionInfo { Version = DefaultVersion, RevisionGuid = "0" };
var workingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); var workingFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
var clrHash = new CommandLineRunner(); var clrHash = new CommandLineRunner();
var clrTags = new CommandLineRunner(); var clrTags = new CommandLineRunner();
@ -130,19 +133,11 @@ namespace UpdateAssemblyInfo
{ {
throw new Exception("Error: Invalid Git version tag (should number.number.number): '" + clrTags.Result + "'"); throw new Exception("Error: Invalid Git version tag (should number.number.number): '" + clrTags.Result + "'");
} }
versionInfo.RevisionGuid = clrHash.Result;
version.RevisionGuid = clrHash.Result; versionInfo.Version = clrTags.Result.Substring(0, clrTags.Result.LastIndexOf('-'));
versionInfo.Version = versionInfo.Version.Replace("-", ".");
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") return versionInfo;
{
Console.WriteLine("WARNING: Could not run Git - build number will be 9999!");
}
return version;
} }
private static int Main(string[] args) private static int Main(string[] args)
@ -159,17 +154,30 @@ namespace UpdateAssemblyInfo
{ {
var seTemplateFileName = Environment.GetCommandLineArgs()[1]; var seTemplateFileName = Environment.GetCommandLineArgs()[1];
var libSeTmplateFileName = Environment.GetCommandLineArgs()[2]; var libSeTmplateFileName = Environment.GetCommandLineArgs()[2];
//seTemplateFileName = @"C:\data\SubtitleEdit\subtitleedit\src\Properties\AssemblyInfo.cs.template";
//libSeTmplateFileName = @"C:\data\SubtitleEdit\subtitleedit\libse\Properties\AssemblyInfo.cs.template";
Console.Write("Updating version number... "); Console.Write("Updating version number... ");
var newVersion = GetNewVersion(); var newVersionInfo = GetNewVersion();
var oldSeVersion = GetOldVersionNumber(seTemplateFileName); var oldSeVersion = GetOldVersionNumber(seTemplateFileName);
var oldLibSeVersion = GetOldVersionNumber(libSeTmplateFileName); var oldLibSeVersion = GetOldVersionNumber(libSeTmplateFileName);
if (oldSeVersion.RevisionGuid != newVersion.RevisionGuid || oldSeVersion.Version != newVersion.Version || if (oldSeVersion.RevisionGuid != newVersionInfo.RevisionGuid || oldSeVersion.Version != newVersionInfo.Version ||
oldLibSeVersion.RevisionGuid != newVersion.RevisionGuid || oldLibSeVersion.Version != newVersion.Version) oldLibSeVersion.RevisionGuid != newVersionInfo.RevisionGuid || oldLibSeVersion.Version != newVersionInfo.Version)
{ {
Console.WriteLine("updating version number to " + newVersion.Version + " " + newVersion.RevisionGuid); if (newVersionInfo.Version == DefaultVersion)
UpdateAssemblyInfo(seTemplateFileName, newVersion); {
UpdateAssemblyInfo(libSeTmplateFileName, newVersion); Console.WriteLine("Git not found: AssemblyInfo.cs must be manually updated");
}
else
{
Console.WriteLine("updating version number to " + newVersionInfo.Version + " " + newVersionInfo.RevisionGuid);
}
UpdateAssemblyInfo(seTemplateFileName, newVersionInfo);
UpdateAssemblyInfo(libSeTmplateFileName, newVersionInfo);
return 0; return 0;
} }
Console.WriteLine("no changes"); Console.WriteLine("no changes");