Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[assembly: AssemblyVersion("2.3.1.0")]
[assembly: AssemblyFileVersion("2.3.1.0")]
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[assembly: AssemblyFileVersion("2.3.1.0")]
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[assembly: AssemblyFileVersion("2.3.1.0")]
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[<assembly: AssemblyVersion("2.3.1.0")>]
[<assembly: AssemblyFileVersion("2.3.1.0")>]
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[<assembly: AssemblyFileVersion("2.3.1.0")>]
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[<assembly: AssemblyFileVersion("2.3.1.0")>]
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<Assembly: AssemblyVersion("2.3.1.0")>
<Assembly: AssemblyFileVersion("2.3.1.0")>
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<Assembly: AssemblyFileVersion("2.3.1.0")>
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<Assembly: AssemblyFileVersion("2.3.1.0")>
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
17 changes: 12 additions & 5 deletions src/GitVersionExe/AssemblyInfoFileUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AssemblyInfoFileUpdate : IDisposable
{
List<Action> restoreBackupTasks = new List<Action>();
List<Action> cleanupBackupTasks = new List<Action>();

public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVariables variables, IFileSystem fileSystem)
{
if (!args.UpdateAssemblyInfo) return;
Expand Down Expand Up @@ -48,18 +48,24 @@ public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVa
cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo));

var fileContents = fileSystem.ReadAllText(assemblyInfoFile.FullName);
var appendedAttributes = false;
if (!string.IsNullOrWhiteSpace(assemblyVersion))
{
fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString, assemblyInfoFile.Extension);
fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString, assemblyInfoFile.Extension, ref appendedAttributes);
}
fileContents = ReplaceOrAppend(assemblyInfoVersionRegex, fileContents, assemblyInfoVersionString, assemblyInfoFile.Extension);
fileContents = ReplaceOrAppend(assemblyFileVersionRegex, fileContents, assemblyFileVersionString, assemblyInfoFile.Extension);
fileContents = ReplaceOrAppend(assemblyInfoVersionRegex, fileContents, assemblyInfoVersionString, assemblyInfoFile.Extension, ref appendedAttributes);
fileContents = ReplaceOrAppend(assemblyFileVersionRegex, fileContents, assemblyFileVersionString, assemblyInfoFile.Extension, ref appendedAttributes);

if (appendedAttributes)
{
// If we appended any attributes, put a new line after them
fileContents += Environment.NewLine;
}
fileSystem.WriteAllText(assemblyInfoFile.FullName, fileContents);
}
}

static string ReplaceOrAppend(Regex replaceRegex, string inputString, string replaceString, string fileExtension)
static string ReplaceOrAppend(Regex replaceRegex, string inputString, string replaceString, string fileExtension, ref bool appendedAttributes)
{
var assemblyAddFormat = AssemblyVersionInfoTemplates.GetAssemblyInfoAddFormatFor(fileExtension);

Expand All @@ -70,6 +76,7 @@ static string ReplaceOrAppend(Regex replaceRegex, string inputString, string rep
else
{
inputString += Environment.NewLine + string.Format(assemblyAddFormat, replaceString);
appendedAttributes = true;
}

return inputString;
Expand Down