Make sure AssemblyInfo.cs exists when starting from scratch II

This commit is contained in:
niksedk 2015-08-27 23:07:30 +02:00
parent db350534cb
commit 7037fef9e9
2 changed files with 35 additions and 34 deletions

1
.gitignore vendored
View File

@ -25,3 +25,4 @@ SubtitleEdit-*-setup.exe
/src/.nuget/NuGet.exe /src/.nuget/NuGet.exe
/src/.nuget/NuGet.Config /src/.nuget/NuGet.Config
/src/packages/ /src/packages/
/libse/Properties/AssemblyInfo.cs

View File

@ -12,7 +12,7 @@ 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; } public string BuildNumber { get; set; }
} }
private static void UpdateAssemblyInfo(string templateFileName, VersionInfo versionInfo) private static void UpdateAssemblyInfo(string templateFileName, VersionInfo versionInfo)
{ {
@ -44,7 +44,7 @@ namespace UpdateAssemblyInfo
original = original.Substring(0, begin) + versionInfo.Version + original.Remove(0, end); original = original.Substring(0, begin) + versionInfo.Version + original.Remove(0, end);
} }
} }
} }
else if (l.StartsWith("[assembly: AssemblyDescription", StringComparison.Ordinal) || else if (l.StartsWith("[assembly: AssemblyDescription", StringComparison.Ordinal) ||
l.StartsWith("[assembly:AssemblyDescription", StringComparison.Ordinal)) l.StartsWith("[assembly:AssemblyDescription", StringComparison.Ordinal))
{ {
@ -71,46 +71,46 @@ 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" }; var version = new VersionInfo { Version = "1.0.0.0", RevisionGuid = "0", BuildNumber = "0" };
var lines = File.ReadAllLines(subtitleEditTemplateFileName.Replace(".template", string.Empty)); var oldFileName = subtitleEditTemplateFileName.Replace(".template", string.Empty);
foreach (var line in lines) if (File.Exists(oldFileName))
{ {
var l = line.Trim(); var lines = File.ReadAllLines(oldFileName);
while (l.Contains(" ")) foreach (var line in lines)
{ {
l = l.Replace(" ", " "); var l = line.Trim();
} while (l.Contains(" "))
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++; l = l.Replace(" ", " ");
version.Version = l.Substring(begin, end - begin);
version.BuildNumber = version.Version.Substring(version.Version.LastIndexOf('.') + 1);
} }
} if (l.StartsWith("[assembly: AssemblyVersion", StringComparison.Ordinal) ||
else if (l.StartsWith("[assembly: AssemblyDescription", StringComparison.Ordinal) || l.StartsWith("[assembly:AssemblyVersion", StringComparison.Ordinal) ||
l.StartsWith("[assembly:AssemblyDescription", StringComparison.Ordinal)) l.StartsWith("[assembly: AssemblyFileVersion", StringComparison.Ordinal) ||
{ l.StartsWith("[assembly:AssemblyFileVersion", StringComparison.Ordinal))
int begin = l.IndexOf("\"", StringComparison.Ordinal);
int end = l.LastIndexOf("\"", StringComparison.Ordinal);
if (end > begin && begin > 0)
{ {
begin++; int begin = l.IndexOf('"');
version.RevisionGuid = l.Substring(begin, end - begin); 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)) return version;
{
Console.WriteLine("WARNING: Could not find version number - will use 1.0.0");
}
return version;
} }
private static VersionInfo GetNewVersion() private static VersionInfo GetNewVersion()