Skip to content

Commit ce9ef68

Browse files
authored
Merge pull request #930 from JakeGinnivan/AppendLinefeedAfterAssemblyInfoAppends
When new assemblyinfo attributes are appended, add a linefeed after
2 parents 2094cad + 71a48eb commit ce9ef68

10 files changed

+21
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[assembly: AssemblyVersion("2.3.1.0")]
22
[assembly: AssemblyFileVersion("2.3.1.0")]
3-
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
3+
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[assembly: AssemblyFileVersion("2.3.1.0")]
2-
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
2+
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[assembly: AssemblyFileVersion("2.3.1.0")]
2-
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
2+
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[<assembly: AssemblyVersion("2.3.1.0")>]
22
[<assembly: AssemblyFileVersion("2.3.1.0")>]
3-
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
3+
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[<assembly: AssemblyFileVersion("2.3.1.0")>]
2-
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
2+
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[<assembly: AssemblyFileVersion("2.3.1.0")>]
2-
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
2+
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<Assembly: AssemblyVersion("2.3.1.0")>
22
<Assembly: AssemblyFileVersion("2.3.1.0")>
3-
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
3+
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<Assembly: AssemblyFileVersion("2.3.1.0")>
2-
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
2+
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<Assembly: AssemblyFileVersion("2.3.1.0")>
2-
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
2+
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>

src/GitVersionExe/AssemblyInfoFileUpdate.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AssemblyInfoFileUpdate : IDisposable
1313
{
1414
List<Action> restoreBackupTasks = new List<Action>();
1515
List<Action> cleanupBackupTasks = new List<Action>();
16-
16+
1717
public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVariables variables, IFileSystem fileSystem)
1818
{
1919
if (!args.UpdateAssemblyInfo) return;
@@ -48,18 +48,24 @@ public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVa
4848
cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo));
4949

5050
var fileContents = fileSystem.ReadAllText(assemblyInfoFile.FullName);
51+
var appendedAttributes = false;
5152
if (!string.IsNullOrWhiteSpace(assemblyVersion))
5253
{
53-
fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString, assemblyInfoFile.Extension);
54+
fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString, assemblyInfoFile.Extension, ref appendedAttributes);
5455
}
55-
fileContents = ReplaceOrAppend(assemblyInfoVersionRegex, fileContents, assemblyInfoVersionString, assemblyInfoFile.Extension);
56-
fileContents = ReplaceOrAppend(assemblyFileVersionRegex, fileContents, assemblyFileVersionString, assemblyInfoFile.Extension);
56+
fileContents = ReplaceOrAppend(assemblyInfoVersionRegex, fileContents, assemblyInfoVersionString, assemblyInfoFile.Extension, ref appendedAttributes);
57+
fileContents = ReplaceOrAppend(assemblyFileVersionRegex, fileContents, assemblyFileVersionString, assemblyInfoFile.Extension, ref appendedAttributes);
5758

59+
if (appendedAttributes)
60+
{
61+
// If we appended any attributes, put a new line after them
62+
fileContents += Environment.NewLine;
63+
}
5864
fileSystem.WriteAllText(assemblyInfoFile.FullName, fileContents);
5965
}
6066
}
6167

62-
static string ReplaceOrAppend(Regex replaceRegex, string inputString, string replaceString, string fileExtension)
68+
static string ReplaceOrAppend(Regex replaceRegex, string inputString, string replaceString, string fileExtension, ref bool appendedAttributes)
6369
{
6470
var assemblyAddFormat = AssemblyVersionInfoTemplates.GetAssemblyInfoAddFormatFor(fileExtension);
6571

@@ -70,6 +76,7 @@ static string ReplaceOrAppend(Regex replaceRegex, string inputString, string rep
7076
else
7177
{
7278
inputString += Environment.NewLine + string.Format(assemblyAddFormat, replaceString);
79+
appendedAttributes = true;
7380
}
7481

7582
return inputString;

0 commit comments

Comments
 (0)