diff --git a/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs b/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs index 0afaa644a1..8348dc9f72 100644 --- a/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs +++ b/src/GitVersionTask.Tests/InvalidFileCheckerTests.cs @@ -98,6 +98,21 @@ public void VerifyCommentWorksCSharp([Values("AssemblyVersion", "AssemblyFileVer FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile); } + [Test] + public void VerifyCommentWithNoNewLineAtEndWorksCSharp([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute) + { + using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.cs"))) + { + writer.Write(@" +using System; +using System.Reflection; + +//[assembly: {0}(""1.0.0.0"")]", attribute); + } + + FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile); + } + [Test] public void VerifyStringWorksCSharp([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute) { @@ -186,6 +201,21 @@ Imports System.Reflection FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile); } + [Test] + public void VerifyCommentWithNoNewLineAtEndWorksVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute) + { + using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.vb"))) + { + writer.Write(@" +Imports System +Imports System.Reflection + +'", attribute); + } + + FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile); + } + [Test] public void VerifyStringWorksVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute) { diff --git a/src/GitVersionTask/FileHelper.cs b/src/GitVersionTask/FileHelper.cs index 1bfea18ced..e94149af97 100644 --- a/src/GitVersionTask/FileHelper.cs +++ b/src/GitVersionTask/FileHelper.cs @@ -97,6 +97,8 @@ private static bool CSharpFileContainsVersionAttribute(string compileFile, strin var combine = Path.Combine(Path.GetDirectoryName(projectFile), compileFile); var allText = File.ReadAllText(combine); + allText += System.Environment.NewLine; // Always add a new line, this handles the case for when a file ends with the EOF marker and no new line. If you don't have this newline, the regex will match commented out Assembly*Version tags on the last line. + var blockComments = @"/\*(.*?)\*/"; var lineComments = @"//(.*?)\r?\n"; var strings = @"""((\\[^\n]|[^""\n])*)"""; @@ -123,6 +125,8 @@ private static bool VisualBasicFileContainsVersionAttribute(string compileFile, var combine = Path.Combine(Path.GetDirectoryName(projectFile), compileFile); var allText = File.ReadAllText(combine); + allText += System.Environment.NewLine; // Always add a new line, this handles the case for when a file ends with the EOF marker and no new line. If you don't have this newline, the regex will match commented out Assembly*Version tags on the last line. + var lineComments = @"'(.*?)\r?\n"; var strings = @"""((\\[^\n]|[^""\n])*)""";