Skip to content

Commit f39f25f

Browse files
committed
Merge branch 'support/5.x' into main
2 parents 3b6239d + 00cf960 commit f39f25f

File tree

10 files changed

+198
-14
lines changed

10 files changed

+198
-14
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127
if_false: github-check
128128
-
129129
name: '[Remark Lint]'
130-
uses: reviewdog/action-remark-lint@v5.4
130+
uses: reviewdog/action-remark-lint@v5.6
131131
with:
132132
github_token: ${{ secrets.GITHUB_TOKEN }}
133133
reporter: ${{ steps.reporter.outputs.value }}

docs/input/docs/reference/build-servers/index.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ RedirectFrom:
1212
<p>
1313
Depending on the Build Server being used, i.e. TeamCity, Jenkins, etc,
1414
GitVersion might need to extra repository information in order to work
15-
correctly. In has knowledge of most of the main CI Providers, and when
16-
instructed to do so, it will fetch the necessary information in order to
15+
correctly. GitVersion has knowledge of most of the main CI Providers, and when
16+
instructed to do so, will fetch the necessary information in order to
1717
correctly assert the semantic version number.
1818
</p>
1919

src/Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
<PackageVersion_MicrosoftExtensions>6.0.0</PackageVersion_MicrosoftExtensions>
3838
<PackageVersion_MicrosoftJson>6.0.0</PackageVersion_MicrosoftJson>
3939
<PackageVersion_MicrosoftTextEncoding>6.0.0</PackageVersion_MicrosoftTextEncoding>
40-
<PackageVersion_MsBuild>17.1.0</PackageVersion_MsBuild>
40+
<PackageVersion_MsBuild>17.2.0</PackageVersion_MsBuild>
4141

42-
<PackageVersion_MicrosoftTestSdk>17.1.0</PackageVersion_MicrosoftTestSdk>
42+
<PackageVersion_MicrosoftTestSdk>17.2.0</PackageVersion_MicrosoftTestSdk>
4343
<PackageVersion_NSubstitute>4.3.0</PackageVersion_NSubstitute>
4444
<PackageVersion_CoverletMsBuild>3.1.2</PackageVersion_CoverletMsBuild>
4545
<PackageVersion_NUnit>3.13.3</PackageVersion_NUnit>

src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="Buildalyzer" Version="4.1.2" />
19-
<PackageReference Include="MSBuild.ProjectCreation" Version="6.3.3" />
19+
<PackageReference Include="MSBuild.ProjectCreation" Version="8.0.0" />
2020
<PackageReference Include="LibGit2Sharp" Version="$(PackageVersion_LibGit2Sharp)" />
2121
</ItemGroup>
2222

src/GitVersion.MsBuild.Tests/Tasks/GenerateGitVersionInformationTest.cs

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,108 @@ public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildI
100100
fileContent.ShouldContain($@"{nameof(VersionVariables.FullSemVer)} = ""1.0.1+1""");
101101
}
102102

103-
private static void AddGenerateGitVersionInformationTask(ProjectCreator project, string targetToRun, string taskName, string outputProperty)
103+
[Test]
104+
public void GenerateGitVersionInformationTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExist()
105+
{
106+
var task = new GenerateGitVersionInformation { IntermediateOutputPath = Guid.NewGuid().ToString("N") };
107+
108+
using var result = ExecuteMsBuildTask(task);
109+
110+
result.Success.ShouldBe(true);
111+
result.Errors.ShouldBe(0);
112+
result.Task.GitVersionInformationFilePath.ShouldNotBeNull();
113+
114+
var fileContent = File.ReadAllText(result.Task.GitVersionInformationFilePath);
115+
fileContent.ShouldContain($@"{nameof(VersionVariables.Major)} = ""1""");
116+
fileContent.ShouldContain($@"{nameof(VersionVariables.Minor)} = ""2""");
117+
fileContent.ShouldContain($@"{nameof(VersionVariables.Patch)} = ""4""");
118+
fileContent.ShouldContain($@"{nameof(VersionVariables.MajorMinorPatch)} = ""1.2.4""");
119+
fileContent.ShouldContain($@"{nameof(VersionVariables.FullSemVer)} = ""1.2.4+1""");
120+
}
121+
122+
[Test]
123+
public void GenerateGitVersionInformationTaskShouldCreateFileInBuildServerWhenIntermediateOutputPathDoesNotExist()
124+
{
125+
var task = new GenerateGitVersionInformation { IntermediateOutputPath = Guid.NewGuid().ToString("N") };
126+
127+
using var result = ExecuteMsBuildTaskInAzurePipeline(task);
128+
129+
result.Success.ShouldBe(true);
130+
result.Errors.ShouldBe(0);
131+
result.Task.GitVersionInformationFilePath.ShouldNotBeNull();
132+
133+
var fileContent = File.ReadAllText(result.Task.GitVersionInformationFilePath);
134+
fileContent.ShouldContain($@"{nameof(VersionVariables.Major)} = ""1""");
135+
fileContent.ShouldContain($@"{nameof(VersionVariables.Minor)} = ""0""");
136+
fileContent.ShouldContain($@"{nameof(VersionVariables.Patch)} = ""1""");
137+
fileContent.ShouldContain($@"{nameof(VersionVariables.MajorMinorPatch)} = ""1.0.1""");
138+
fileContent.ShouldContain($@"{nameof(VersionVariables.FullSemVer)} = ""1.0.1+1""");
139+
}
140+
141+
[Test]
142+
public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExist()
143+
{
144+
const string taskName = nameof(GenerateGitVersionInformation);
145+
const string outputProperty = nameof(GenerateGitVersionInformation.GitVersionInformationFilePath);
146+
var randDir = Guid.NewGuid().ToString("N");
147+
148+
using var result = ExecuteMsBuildExe(project => AddGenerateGitVersionInformationTask(project, taskName, taskName, outputProperty, Path.Combine("$(MSBuildProjectDirectory)", randDir)));
149+
150+
result.ProjectPath.ShouldNotBeNullOrWhiteSpace();
151+
result.MsBuild.Count.ShouldBeGreaterThan(0);
152+
result.MsBuild.OverallSuccess.ShouldBe(true);
153+
result.MsBuild.ShouldAllBe(x => x.Succeeded);
154+
result.Output.ShouldNotBeNullOrWhiteSpace();
155+
156+
var generatedFilePath = PathHelper.Combine(Path.GetDirectoryName(result.ProjectPath), randDir, "GitVersionInformation.g.cs");
157+
result.Output.ShouldContain($"{outputProperty}: {generatedFilePath}");
158+
159+
var fileContent = File.ReadAllText(generatedFilePath);
160+
fileContent.ShouldContain($@"{nameof(VersionVariables.Major)} = ""1""");
161+
fileContent.ShouldContain($@"{nameof(VersionVariables.Minor)} = ""2""");
162+
fileContent.ShouldContain($@"{nameof(VersionVariables.Patch)} = ""4""");
163+
fileContent.ShouldContain($@"{nameof(VersionVariables.MajorMinorPatch)} = ""1.2.4""");
164+
fileContent.ShouldContain($@"{nameof(VersionVariables.FullSemVer)} = ""1.2.4+1""");
165+
}
166+
167+
[Test]
168+
public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExistInBuildServer()
169+
{
170+
const string taskName = nameof(GenerateGitVersionInformation);
171+
const string outputProperty = nameof(GenerateGitVersionInformation.GitVersionInformationFilePath);
172+
var randDir = Guid.NewGuid().ToString("N");
173+
174+
using var result = ExecuteMsBuildExeInAzurePipeline(project => AddGenerateGitVersionInformationTask(project, taskName, taskName, outputProperty, Path.Combine("$(MSBuildProjectDirectory)", randDir)));
175+
176+
result.ProjectPath.ShouldNotBeNullOrWhiteSpace();
177+
result.MsBuild.Count.ShouldBeGreaterThan(0);
178+
result.MsBuild.OverallSuccess.ShouldBe(true);
179+
result.MsBuild.ShouldAllBe(x => x.Succeeded);
180+
result.Output.ShouldNotBeNullOrWhiteSpace();
181+
182+
var generatedFilePath = PathHelper.Combine(Path.GetDirectoryName(result.ProjectPath), randDir, "GitVersionInformation.g.cs");
183+
result.Output.ShouldContain($"{outputProperty}: {generatedFilePath}");
184+
185+
var fileContent = File.ReadAllText(generatedFilePath);
186+
fileContent.ShouldContain($@"{nameof(VersionVariables.Major)} = ""1""");
187+
fileContent.ShouldContain($@"{nameof(VersionVariables.Minor)} = ""0""");
188+
fileContent.ShouldContain($@"{nameof(VersionVariables.Patch)} = ""1""");
189+
fileContent.ShouldContain($@"{nameof(VersionVariables.MajorMinorPatch)} = ""1.0.1""");
190+
fileContent.ShouldContain($@"{nameof(VersionVariables.FullSemVer)} = ""1.0.1+1""");
191+
}
192+
193+
private static void AddGenerateGitVersionInformationTask(ProjectCreator project, string targetToRun, string taskName, string outputProperty, string intermediateOutputPath = "$(MSBuildProjectDirectory)")
104194
{
105195
var assemblyFileLocation = typeof(GitVersionTaskBase).Assembly.Location;
106196
project.UsingTaskAssemblyFile(taskName, assemblyFileLocation)
107197
.Property("GenerateAssemblyInfo", "false")
108198
.Target(targetToRun, beforeTargets: "CoreCompile;GetAssemblyVersion;GenerateNuspec")
109-
.Task(taskName, parameters: new Dictionary<string, string>
199+
.Task(taskName, parameters: new Dictionary<string, string?>
110200
{
111201
{ "SolutionDirectory", "$(MSBuildProjectDirectory)" },
112202
{ "VersionFile", "$(MSBuildProjectDirectory)/gitversion.json" },
113203
{ "ProjectFile", "$(MSBuildProjectFullPath)" },
114-
{ "IntermediateOutputPath", "$(MSBuildProjectDirectory)" },
204+
{ "IntermediateOutputPath", intermediateOutputPath },
115205
{ "Language", "$(Language)" }
116206
})
117207
.TaskOutputProperty(outputProperty, outputProperty)

src/GitVersion.MsBuild.Tests/Tasks/GetVersionTaskTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private static void AddGetVersionTask(ProjectCreator project, string targetToRun
100100
project.UsingTaskAssemblyFile(taskName, assemblyFileLocation)
101101
.Property("GenerateAssemblyInfo", "false")
102102
.Target(targetToRun, beforeTargets: "CoreCompile;GetAssemblyVersion;GenerateNuspec")
103-
.Task(taskName, parameters: new Dictionary<string, string>
103+
.Task(taskName, parameters: new Dictionary<string, string?>
104104
{
105105
{ "SolutionDirectory", "$(MSBuildProjectDirectory)" },
106106
{ "VersionFile", "$(MSBuildProjectDirectory)/gitversion.json" }

src/GitVersion.MsBuild.Tests/Tasks/UpdateAssemblyInfoTaskTest.cs

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,92 @@ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildInBuildServe
8383
fileContent.ShouldContain(@"[assembly: AssemblyVersion(""1.0.1.0"")]");
8484
}
8585

86-
private static void AddUpdateAssemblyInfoTask(ProjectCreator project, string targetToRun, string taskName, string outputProperty)
86+
[Test]
87+
public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExist()
88+
{
89+
var task = new UpdateAssemblyInfo { IntermediateOutputPath = Guid.NewGuid().ToString("N") };
90+
91+
using var result = ExecuteMsBuildTask(task);
92+
93+
result.Success.ShouldBe(true);
94+
result.Errors.ShouldBe(0);
95+
result.Task.AssemblyInfoTempFilePath.ShouldNotBeNull();
96+
97+
var fileContent = File.ReadAllText(result.Task.AssemblyInfoTempFilePath);
98+
fileContent.ShouldContain(@"[assembly: AssemblyVersion(""1.2.4.0"")]");
99+
}
100+
101+
[Test]
102+
public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExistInBuildServer()
103+
{
104+
var task = new UpdateAssemblyInfo { IntermediateOutputPath = Guid.NewGuid().ToString("N") };
105+
106+
using var result = ExecuteMsBuildTaskInAzurePipeline(task);
107+
108+
result.Success.ShouldBe(true);
109+
result.Errors.ShouldBe(0);
110+
result.Task.AssemblyInfoTempFilePath.ShouldNotBeNull();
111+
112+
var fileContent = File.ReadAllText(result.Task.AssemblyInfoTempFilePath);
113+
fileContent.ShouldContain(@"[assembly: AssemblyVersion(""1.0.1.0"")]");
114+
}
115+
116+
[Test]
117+
public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExist()
118+
{
119+
const string taskName = nameof(UpdateAssemblyInfo);
120+
const string outputProperty = nameof(UpdateAssemblyInfo.AssemblyInfoTempFilePath);
121+
var randDir = Guid.NewGuid().ToString("N");
122+
123+
using var result = ExecuteMsBuildExe(project => AddUpdateAssemblyInfoTask(project, taskName, taskName, outputProperty, Path.Combine("$(MSBuildProjectDirectory)", randDir)));
124+
125+
result.ProjectPath.ShouldNotBeNullOrWhiteSpace();
126+
result.MsBuild.Count.ShouldBeGreaterThan(0);
127+
result.MsBuild.OverallSuccess.ShouldBe(true);
128+
result.MsBuild.ShouldAllBe(x => x.Succeeded);
129+
result.Output.ShouldNotBeNullOrWhiteSpace();
130+
131+
var generatedFilePath = PathHelper.Combine(Path.GetDirectoryName(result.ProjectPath), randDir, "AssemblyInfo.g.cs");
132+
result.Output.ShouldContain($"{outputProperty}: {generatedFilePath}");
133+
134+
var fileContent = File.ReadAllText(generatedFilePath);
135+
fileContent.ShouldContain(@"[assembly: AssemblyVersion(""1.2.4.0"")]");
136+
}
137+
138+
[Test]
139+
public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExistInBuildServer()
140+
{
141+
const string taskName = nameof(UpdateAssemblyInfo);
142+
const string outputProperty = nameof(UpdateAssemblyInfo.AssemblyInfoTempFilePath);
143+
var randDir = Guid.NewGuid().ToString("N");
144+
145+
using var result = ExecuteMsBuildExeInAzurePipeline(project => AddUpdateAssemblyInfoTask(project, taskName, taskName, outputProperty, Path.Combine("$(MSBuildProjectDirectory)", randDir)));
146+
147+
result.ProjectPath.ShouldNotBeNullOrWhiteSpace();
148+
result.MsBuild.Count.ShouldBeGreaterThan(0);
149+
result.MsBuild.OverallSuccess.ShouldBe(true);
150+
result.MsBuild.ShouldAllBe(x => x.Succeeded);
151+
result.Output.ShouldNotBeNullOrWhiteSpace();
152+
153+
var generatedFilePath = PathHelper.Combine(Path.GetDirectoryName(result.ProjectPath), randDir, "AssemblyInfo.g.cs");
154+
result.Output.ShouldContain($"{outputProperty}: {generatedFilePath}");
155+
156+
var fileContent = File.ReadAllText(generatedFilePath);
157+
fileContent.ShouldContain(@"[assembly: AssemblyVersion(""1.0.1.0"")]");
158+
}
159+
160+
private static void AddUpdateAssemblyInfoTask(ProjectCreator project, string targetToRun, string taskName, string outputProperty, string intermediateOutputPath = "$(MSBuildProjectDirectory)")
87161
{
88162
var assemblyFileLocation = typeof(GitVersionTaskBase).Assembly.Location;
89163
project.UsingTaskAssemblyFile(taskName, assemblyFileLocation)
90164
.Property("GenerateAssemblyInfo", "false")
91165
.Target(targetToRun, beforeTargets: "CoreCompile;GetAssemblyVersion;GenerateNuspec")
92-
.Task(taskName, parameters: new Dictionary<string, string>
166+
.Task(taskName, parameters: new Dictionary<string, string?>
93167
{
94168
{ "SolutionDirectory", "$(MSBuildProjectDirectory)" },
95169
{ "VersionFile", "$(MSBuildProjectDirectory)/gitversion.json" },
96170
{ "ProjectFile", "$(MSBuildProjectFullPath)" },
97-
{ "IntermediateOutputPath", "$(MSBuildProjectDirectory)" },
171+
{ "IntermediateOutputPath", intermediateOutputPath },
98172
{ "Language", "$(Language)" },
99173
{ "CompileFiles", "@(Compile)" }
100174
})

src/GitVersion.MsBuild.Tests/Tasks/WriteVersionInfoTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private static void AddWriteVersionInfoToBuildLogTask(ProjectCreator project, st
124124
project.UsingTaskAssemblyFile(taskName, assemblyFileLocation)
125125
.Property("GenerateAssemblyInfo", "false")
126126
.Target(targetToRun, beforeTargets: "CoreCompile;GetAssemblyVersion;GenerateNuspec")
127-
.Task(taskName, parameters: new Dictionary<string, string>
127+
.Task(taskName, parameters: new Dictionary<string, string?>
128128
{
129129
{ "SolutionDirectory", "$(MSBuildProjectDirectory)" },
130130
{ "VersionFile", "$(MSBuildProjectDirectory)/gitversion.json" }

src/GitVersion.MsBuild/GitVersionTaskExecutor.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public void UpdateAssemblyInfo(UpdateAssemblyInfo task)
3535
FileHelper.DeleteTempFiles();
3636
FileHelper.CheckForInvalidFiles(task.CompileFiles, task.ProjectFile);
3737

38+
if (!string.IsNullOrEmpty(task.IntermediateOutputPath))
39+
{
40+
// Ensure provided output path exists first. Fixes issue #2815.
41+
fileSystem.CreateDirectory(task.IntermediateOutputPath);
42+
}
43+
3844
var fileWriteInfo = task.IntermediateOutputPath.GetFileWriteInfo(task.Language, task.ProjectFile, "AssemblyInfo");
3945
task.AssemblyInfoTempFilePath = PathHelper.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName);
4046

@@ -50,6 +56,13 @@ public void UpdateAssemblyInfo(UpdateAssemblyInfo task)
5056
public void GenerateGitVersionInformation(GenerateGitVersionInformation task)
5157
{
5258
var versionVariables = VersionVariables.FromFile(task.VersionFile, fileSystem);
59+
60+
if (!string.IsNullOrEmpty(task.IntermediateOutputPath))
61+
{
62+
// Ensure provided output path exists first. Fixes issue #2815.
63+
fileSystem.CreateDirectory(task.IntermediateOutputPath);
64+
}
65+
5366
var fileWriteInfo = task.IntermediateOutputPath.GetFileWriteInfo(task.Language, task.ProjectFile, "GitVersionInformation");
5467
task.GitVersionInformationFilePath = PathHelper.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName);
5568

src/global.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sdk": {
3+
"version": "6.0.0",
4+
"rollForward": "latestMajor",
5+
"allowPrerelease": true
6+
}
7+
}

0 commit comments

Comments
 (0)