mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 12:44:46 +01:00
Making version maintaining easier (only update in SubtitleEdit AssemblyInfo.cs - libse auto updated)
This commit is contained in:
parent
a546bdacb1
commit
6e438005b0
@ -38,9 +38,9 @@ IF NOT EXIST "src\UpdateAssemblyInfo\bin\Release\UpdateAssemblyInfo.exe" IF NOT
|
||||
)
|
||||
|
||||
IF EXIST "src\UpdateAssemblyInfo\bin\Release\UpdateAssemblyInfo.exe" (
|
||||
"src\UpdateAssemblyInfo\bin\Release\UpdateAssemblyInfo.exe" "src\Properties\AssemblyInfo.cs.template" "src\Properties\AssemblyInfo.cs"
|
||||
"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" "src\Properties\AssemblyInfo.cs"
|
||||
"src\UpdateAssemblyInfo\bin\Debug\UpdateAssemblyInfo.exe" "src\Properties\AssemblyInfo.cs.template" "libse\Properties\AssemblyInfo.cs.template"
|
||||
)
|
||||
|
||||
IF %ERRORLEVEL% NEQ 0 (
|
||||
|
@ -437,6 +437,11 @@
|
||||
<Compile Include="ZipExtractor.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>IF NOT EXIST "$(ProjectDir)Properties\AssemblyInfo.cs" (
|
||||
COPY "$(ProjectDir)Properties\AssemblyInfo.cs.template" "$(ProjectDir)Properties\AssemblyInfo.cs"
|
||||
)</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
@ -1,35 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("libse")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("libse")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("eab3b9db-0f82-4843-982b-05a4c51888a2")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
15
libse/Properties/AssemblyInfo.cs.template
Normal file
15
libse/Properties/AssemblyInfo.cs.template
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("libse")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("libse")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("eab3b9db-0f82-4843-982b-05a4c51888a2")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
@ -1547,7 +1547,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
{
|
||||
get
|
||||
{
|
||||
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
return Assembly.GetEntryAssembly().GetName().Version.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1555,15 +1555,14 @@ namespace Nikse.SubtitleEdit.Core
|
||||
{
|
||||
get
|
||||
{
|
||||
Assembly assy = Assembly.GetExecutingAssembly();
|
||||
String assyName = assy.GetName().Name;
|
||||
bool isdef = Attribute.IsDefined(assy, typeof(AssemblyDescriptionAttribute));
|
||||
if (isdef)
|
||||
var assembly = Assembly.GetEntryAssembly();
|
||||
string assemblyName = assembly.GetName().Name;
|
||||
if (Attribute.IsDefined(assembly, typeof(AssemblyDescriptionAttribute)))
|
||||
{
|
||||
Console.WriteLine(assyName);
|
||||
var adAttr = (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(assy, typeof(AssemblyDescriptionAttribute));
|
||||
if (adAttr != null)
|
||||
return adAttr.Description;
|
||||
Console.WriteLine(assemblyName);
|
||||
var descriptionAttribute = (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(assembly, typeof(AssemblyDescriptionAttribute));
|
||||
if (descriptionAttribute != null)
|
||||
return descriptionAttribute.Description;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -7,96 +7,171 @@ namespace UpdateAssemblyInfo
|
||||
internal class Program
|
||||
{
|
||||
|
||||
private class Template
|
||||
private class VersionInfo
|
||||
{
|
||||
private string templateFile;
|
||||
private string templateText;
|
||||
|
||||
public Template(string path)
|
||||
{
|
||||
templateFile = path;
|
||||
public string Version { get; set; }
|
||||
public string RevisionGuid { get; set; }
|
||||
public string BuildNumber { get; set; }
|
||||
}
|
||||
|
||||
public void Replace(string source, string replacement)
|
||||
private static void UpdateAssemblyInfo(string templateFileName, VersionInfo versionInfo)
|
||||
{
|
||||
if (templateText == null)
|
||||
var lines = File.ReadAllLines(templateFileName);
|
||||
var sb = new StringBuilder();
|
||||
bool change = false;
|
||||
foreach (var line in lines)
|
||||
{
|
||||
templateText = File.ReadAllText(templateFile);
|
||||
var original = line;
|
||||
var l = line.Trim();
|
||||
while (l.Contains(" "))
|
||||
{
|
||||
l = l.Replace(" ", " ");
|
||||
}
|
||||
if (l.StartsWith("[assembly: AssemblyVersion", StringComparison.Ordinal) ||
|
||||
l.StartsWith("[assembly:AssemblyVersion", StringComparison.Ordinal) ||
|
||||
l.StartsWith("[assembly: AssemblyFileVersion", StringComparison.Ordinal) ||
|
||||
l.StartsWith("[assembly:AssemblyFileVersion", StringComparison.Ordinal))
|
||||
{
|
||||
int begin = original.IndexOf('"');
|
||||
int end = original.LastIndexOf('"');
|
||||
if (end > begin && begin > 0)
|
||||
{
|
||||
begin++;
|
||||
string oldVersion = original.Substring(begin, end - begin);
|
||||
if (oldVersion != versionInfo.Version)
|
||||
{
|
||||
change = true;
|
||||
original = original.Substring(0, begin) + versionInfo.Version + original.Remove(0, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (l.StartsWith("[assembly: AssemblyDescription", StringComparison.Ordinal) ||
|
||||
l.StartsWith("[assembly:AssemblyDescription", StringComparison.Ordinal))
|
||||
{
|
||||
int begin = original.IndexOf('"');
|
||||
int end = original.LastIndexOf('"');
|
||||
if (end > begin && begin > 0)
|
||||
{
|
||||
begin++;
|
||||
string oldVersion = original.Substring(begin, end - begin);
|
||||
if (oldVersion != versionInfo.Version)
|
||||
{
|
||||
change = true;
|
||||
original = original.Substring(0, begin) + versionInfo.RevisionGuid + original.Remove(0, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.AppendLine(original);
|
||||
}
|
||||
if (change)
|
||||
{
|
||||
File.WriteAllText(templateFileName.Replace(".template", string.Empty), sb.ToString().Trim());
|
||||
}
|
||||
templateText = templateText.Replace(source, replacement);
|
||||
}
|
||||
|
||||
public void Save(string target)
|
||||
private static VersionInfo GetOldVersionNumber(string subtitleEditTemplateFileName)
|
||||
{
|
||||
File.WriteAllText(target, templateText, Encoding.UTF8);
|
||||
var version = new VersionInfo { Version = "1.0.0.0", RevisionGuid = "0" };
|
||||
var lines = File.ReadAllLines(subtitleEditTemplateFileName.Replace(".template", string.Empty));
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var l = line.Trim();
|
||||
while (l.Contains(" "))
|
||||
{
|
||||
l = l.Replace(" ", " ");
|
||||
}
|
||||
if (l.StartsWith("[assembly: AssemblyVersion", StringComparison.Ordinal) ||
|
||||
l.StartsWith("[assembly:AssemblyVersion", StringComparison.Ordinal) ||
|
||||
l.StartsWith("[assembly: AssemblyFileVersion", StringComparison.Ordinal) ||
|
||||
l.StartsWith("[assembly:AssemblyFileVersion", StringComparison.Ordinal))
|
||||
{
|
||||
int begin = l.IndexOf('"');
|
||||
int end = l.LastIndexOf('"');
|
||||
if (end > begin && begin > 0)
|
||||
{
|
||||
begin++;
|
||||
version.Version = l.Substring(begin, end - begin);
|
||||
version.BuildNumber = version.Version.Substring(version.Version.LastIndexOf('.') + 1);
|
||||
}
|
||||
}
|
||||
else if (l.StartsWith("[assembly: AssemblyDescription", StringComparison.Ordinal) ||
|
||||
l.StartsWith("[assembly:AssemblyDescription", StringComparison.Ordinal))
|
||||
{
|
||||
int begin = l.IndexOf("\"", StringComparison.Ordinal);
|
||||
int end = l.LastIndexOf("\"", StringComparison.Ordinal);
|
||||
if (end > begin && begin > 0)
|
||||
{
|
||||
begin++;
|
||||
version.RevisionGuid = l.Substring(begin, end - begin);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(version.Version))
|
||||
{
|
||||
Console.WriteLine("WARNING: Could not find version number - will use 1.0.0");
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
private static VersionInfo GetNewVersion()
|
||||
{
|
||||
var version = new VersionInfo { Version = "1.0.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))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
var myName = Environment.GetCommandLineArgs()[0];
|
||||
myName = Path.GetFileNameWithoutExtension(string.IsNullOrWhiteSpace(myName)
|
||||
? System.Reflection.Assembly.GetEntryAssembly().Location
|
||||
: myName);
|
||||
|
||||
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)
|
||||
");
|
||||
Console.WriteLine("Usage: " + myName + " <se-assmbly-template> <libse-assmbly-template>");
|
||||
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);
|
||||
try
|
||||
{
|
||||
var seTemplateFileName = Environment.GetCommandLineArgs()[1];
|
||||
var libSeTmplateFileName = Environment.GetCommandLineArgs()[2];
|
||||
Console.Write("Updating version number... ");
|
||||
var oldSeVersion = GetOldVersionNumber(seTemplateFileName);
|
||||
var oldLibSeVersion = GetOldVersionNumber(libSeTmplateFileName);
|
||||
var newVersion = GetNewVersion();
|
||||
|
||||
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))
|
||||
if (oldSeVersion.RevisionGuid != newVersion.RevisionGuid || oldSeVersion.Version != newVersion.Version ||
|
||||
oldLibSeVersion.RevisionGuid != newVersion.RevisionGuid || oldLibSeVersion.Version != newVersion.Version)
|
||||
{
|
||||
try
|
||||
{
|
||||
template.Replace("[GITHASH]", clrHash.Result);
|
||||
if (clrTags.Result.IndexOf('-') < 0)
|
||||
clrTags.Result += "-0";
|
||||
template.Replace("[REVNO]", clrTags.Result.Split('-')[1]);
|
||||
template.Save(targetFile);
|
||||
Console.WriteLine("updating version number to " + newVersion.Version + " " + newVersion.RevisionGuid);
|
||||
UpdateAssemblyInfo(seTemplateFileName, newVersion);
|
||||
UpdateAssemblyInfo(libSeTmplateFileName, newVersion);
|
||||
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);
|
||||
Console.WriteLine("no changes");
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception exception)
|
||||
{
|
||||
exceptionMessage = ex.Message;
|
||||
Console.WriteLine("Something bad happened when running " + myName + ": " + exception.Message + Environment.NewLine + exception.StackTrace);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Console.WriteLine(myName + ": Could not update AssemblyInfo: " + exceptionMessage);
|
||||
Console.WriteLine(" - Git folder: " + workingFolder);
|
||||
Console.WriteLine(" - Template: " + templateFile);
|
||||
Console.WriteLine(" - Target: " + targetFile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static string GetGitPath()
|
||||
{
|
||||
@ -130,6 +205,10 @@ namespace UpdateAssemblyInfo
|
||||
}
|
||||
|
||||
var envSystemDrive = Environment.GetEnvironmentVariable("SystemDrive");
|
||||
if (string.IsNullOrEmpty(envSystemDrive))
|
||||
{
|
||||
throw new Exception("Environment.GetEnvironmentVariable('SystemDrive') returned null!");
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(envSystemDrive))
|
||||
{
|
||||
var path = Path.Combine(envSystemDrive, "Program Files", gitPath);
|
||||
@ -163,8 +242,9 @@ namespace UpdateAssemblyInfo
|
||||
return path;
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception("UpdateAssemblyInfo - GetGitPath: " + exception.Message);
|
||||
}
|
||||
|
||||
Console.WriteLine("WARNING: Might not be able to run Git command line tool!");
|
||||
|
Loading…
Reference in New Issue
Block a user