Skip to content

Commit b40507d

Browse files
Jeff PeirsonJeff Peirson
authored andcommitted
Applied same IntermediateOutputPath fix for UpdateAssemblyInfo task
1 parent 8386c6d commit b40507d

File tree

2 files changed

+87
-3
lines changed

2 files changed

+87
-3
lines changed

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

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,85 @@ public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildInBuildServe
8787
fileContent.ShouldContain(@"[assembly: AssemblyVersion(""1.0.1.0"")]");
8888
}
8989

90-
private static void AddUpdateAssemblyInfoTask(ProjectCreator project, string targetToRun, string taskName, string outputProperty)
90+
[Test]
91+
public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExist()
92+
{
93+
var task = new UpdateAssemblyInfo { IntermediateOutputPath = Guid.NewGuid().ToString("N") };
94+
95+
using var result = ExecuteMsBuildTask(task);
96+
97+
result.Success.ShouldBe(true);
98+
result.Errors.ShouldBe(0);
99+
result.Task.AssemblyInfoTempFilePath.ShouldNotBeNull();
100+
101+
var fileContent = File.ReadAllText(result.Task.AssemblyInfoTempFilePath);
102+
fileContent.ShouldContain(@"[assembly: AssemblyVersion(""1.2.4.0"")]");
103+
}
104+
105+
[Test]
106+
public void UpdateAssemblyInfoTaskShouldCreateFileWhenIntermediateOutputPathDoesNotExistInBuildServer()
107+
{
108+
var task = new UpdateAssemblyInfo { IntermediateOutputPath = Guid.NewGuid().ToString("N") };
109+
110+
using var result = ExecuteMsBuildTaskInAzurePipeline(task);
111+
112+
result.Success.ShouldBe(true);
113+
result.Errors.ShouldBe(0);
114+
result.Task.AssemblyInfoTempFilePath.ShouldNotBeNull();
115+
116+
var fileContent = File.ReadAllText(result.Task.AssemblyInfoTempFilePath);
117+
fileContent.ShouldContain(@"[assembly: AssemblyVersion(""1.0.1.0"")]");
118+
}
119+
120+
[Test]
121+
[Category(NoNet48)]
122+
[Category(NoMono)]
123+
public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExist()
124+
{
125+
const string taskName = nameof(UpdateAssemblyInfo);
126+
const string outputProperty = nameof(UpdateAssemblyInfo.AssemblyInfoTempFilePath);
127+
var randDir = Guid.NewGuid().ToString("N");
128+
129+
using var result = ExecuteMsBuildExe(project => AddUpdateAssemblyInfoTask(project, taskName, taskName, outputProperty, Path.Combine("$(MSBuildProjectDirectory)", randDir)));
130+
131+
result.ProjectPath.ShouldNotBeNullOrWhiteSpace();
132+
result.MsBuild.Count.ShouldBeGreaterThan(0);
133+
result.MsBuild.OverallSuccess.ShouldBe(true);
134+
result.MsBuild.ShouldAllBe(x => x.Succeeded);
135+
result.Output.ShouldNotBeNullOrWhiteSpace();
136+
137+
var generatedFilePath = PathHelper.Combine(Path.GetDirectoryName(result.ProjectPath), randDir, "AssemblyInfo.g.cs");
138+
result.Output.ShouldContain($"{outputProperty}: {generatedFilePath}");
139+
140+
var fileContent = File.ReadAllText(generatedFilePath);
141+
fileContent.ShouldContain(@"[assembly: AssemblyVersion(""1.2.4.0"")]");
142+
}
143+
144+
[Test]
145+
[Category(NoNet48)]
146+
[Category(NoMono)]
147+
public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunWithMsBuildAndIntermediateOutputPathDoesNotExistInBuildServer()
148+
{
149+
const string taskName = nameof(UpdateAssemblyInfo);
150+
const string outputProperty = nameof(UpdateAssemblyInfo.AssemblyInfoTempFilePath);
151+
var randDir = Guid.NewGuid().ToString("N");
152+
153+
using var result = ExecuteMsBuildExeInAzurePipeline(project => AddUpdateAssemblyInfoTask(project, taskName, taskName, outputProperty, Path.Combine("$(MSBuildProjectDirectory)", randDir)));
154+
155+
result.ProjectPath.ShouldNotBeNullOrWhiteSpace();
156+
result.MsBuild.Count.ShouldBeGreaterThan(0);
157+
result.MsBuild.OverallSuccess.ShouldBe(true);
158+
result.MsBuild.ShouldAllBe(x => x.Succeeded);
159+
result.Output.ShouldNotBeNullOrWhiteSpace();
160+
161+
var generatedFilePath = PathHelper.Combine(Path.GetDirectoryName(result.ProjectPath), randDir, "AssemblyInfo.g.cs");
162+
result.Output.ShouldContain($"{outputProperty}: {generatedFilePath}");
163+
164+
var fileContent = File.ReadAllText(generatedFilePath);
165+
fileContent.ShouldContain(@"[assembly: AssemblyVersion(""1.0.1.0"")]");
166+
}
167+
168+
private static void AddUpdateAssemblyInfoTask(ProjectCreator project, string targetToRun, string taskName, string outputProperty, string intermediateOutputPath = "$(MSBuildProjectDirectory)")
91169
{
92170
var assemblyFileLocation = typeof(GitVersionTaskBase).Assembly.Location;
93171
project.UsingTaskAssemblyFile(taskName, assemblyFileLocation)
@@ -98,7 +176,7 @@ private static void AddUpdateAssemblyInfoTask(ProjectCreator project, string tar
98176
{ "SolutionDirectory", "$(MSBuildProjectDirectory)" },
99177
{ "VersionFile", "$(MSBuildProjectDirectory)/gitversion.json" },
100178
{ "ProjectFile", "$(MSBuildProjectFullPath)" },
101-
{ "IntermediateOutputPath", "$(MSBuildProjectDirectory)" },
179+
{ "IntermediateOutputPath", intermediateOutputPath },
102180
{ "Language", "$(Language)" },
103181
{ "CompileFiles", "@(Compile)" }
104182
})

src/GitVersion.MsBuild/GitVersionTaskExecutor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public void UpdateAssemblyInfo(UpdateAssemblyInfo task)
3434
var versionVariables = VersionVariables.FromFile(task.VersionFile, fileSystem);
3535
FileHelper.DeleteTempFiles();
3636
FileHelper.CheckForInvalidFiles(task.CompileFiles, task.ProjectFile);
37+
38+
if (!string.IsNullOrEmpty(task.IntermediateOutputPath))
39+
{
40+
// Ensure provided output path exists first. Fixes issue #2815.
41+
fileSystem.CreateDirectory(task.IntermediateOutputPath);
42+
}
3743

3844
var fileWriteInfo = task.IntermediateOutputPath.GetFileWriteInfo(task.Language, task.ProjectFile, "AssemblyInfo");
3945
task.AssemblyInfoTempFilePath = PathHelper.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName);
@@ -54,7 +60,7 @@ public void GenerateGitVersionInformation(GenerateGitVersionInformation task)
5460
if (!string.IsNullOrEmpty(task.IntermediateOutputPath))
5561
{
5662
// Ensure provided output path exists first. Fixes issue #2815.
57-
this.fileSystem.CreateDirectory(task.IntermediateOutputPath);
63+
fileSystem.CreateDirectory(task.IntermediateOutputPath);
5864
}
5965

6066
var fileWriteInfo = task.IntermediateOutputPath.GetFileWriteInfo(task.Language, task.ProjectFile, "GitVersionInformation");

0 commit comments

Comments
 (0)