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
30 changes: 30 additions & 0 deletions src/GitVersionTask.Tests/InvalidFileCheckerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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

'<Assembly: {0}(""1.0.0.0"")>", attribute);
}

FileHelper.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
}

[Test]
public void VerifyStringWorksVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
{
Expand Down
4 changes: 4 additions & 0 deletions src/GitVersionTask/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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])*)""";
Expand All @@ -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])*)""";

Expand Down