Skip to content

Commit

Permalink
Fix bubbling of TargetOutputs for "Rebuild" calls (#190)
Browse files Browse the repository at this point in the history
* Added meta-target "Rebuild" to the traversal sdk with the appropriate return attribute

The MSBuild task only returns the TargetOutputs items explicitly set by the target called.
If no specific target was called the default target returns their TargetOutput.

Resolves #187

* Pin down dotnet sdk version & adjust pipeline to download via global.json to workaround issue in .NET Core 5 with Nerdbank.GitVersioning
  • Loading branch information
MeikTranel authored Jun 14, 2020
1 parent f1b207c commit 5ab9834
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 2 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ variables:
BinaryLoggerArgs: '"/BinaryLogger:$(Build.SourcesDirectory)\$(ArtifactsDirectoryName)\msbuild.binlog"'
BuildConfiguration: 'Debug'
BuildPlatform: 'Any CPU'
DotNetCoreVersion: '3.1.300'

trigger:
batch: true
Expand All @@ -33,9 +32,9 @@ jobs:
vmImage: windows-latest
steps:
- task: UseDotNet@2
displayName: 'Install .NET Core $(DotNetCoreVersion)'
displayName: 'Install .NET Core from globa.json'
inputs:
version: '$(DotNetCoreVersion)'
useGlobalJson: true

- task: MSBuild@1
displayName: 'Build Solution'
Expand Down
4 changes: 4 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"sdk": {
"version": "3.1.300",
"rollForward": "latestFeature"
},
"msbuild-sdks": {
"Microsoft.Build.NoTargets": "1.0.94"
}
Expand Down
10 changes: 7 additions & 3 deletions src/Traversal.UnitTests/TraversalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,11 @@ public void WorksWhenConfigurationSpecified(string configuration)
result.ShouldBeTrue(customMessage: () => buildOutput.GetConsoleLog());
}

[Fact]
public void CollectsProjectReferenceBuildTargetOutputs()
[Theory]
[InlineData(null)]
[InlineData("Build")]
[InlineData("Rebuild")]
public void CollectsProjectReferenceBuildTargetOutputs(string target)
{
string[] projects = new[]
{
Expand All @@ -325,7 +328,7 @@ public void CollectsProjectReferenceBuildTargetOutputs()
parameters: new Dictionary<string, string>
{
["Projects"] = subTraversalProject.FullPath,
["Targets"] = "Build"
["Targets"] = target
})
.TaskOutputItem("TargetOutputs", "CollectedOutputs")
.TaskMessage("%(CollectedOutputs.Identity)", MessageImportance.High)
Expand All @@ -342,6 +345,7 @@ ProjectCreator GetSkeletonCSProjWithTargetOutputs(string projectName)
.Target("Build", returns: "@(TestReturnItem)")
.TargetItemGroup()
.TargetItemInclude("TestReturnItem", "$(MSBuildThisFileName).dll")
.Target("Clean")
.Save();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Traversal/Sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
ContinueOnError="$([MSBuild]::ValueOrDefault('$(CleanContinueOnError)', '$(ContinueOnError)'))" />
</Target>

<Target Name="Rebuild" DependsOnTargets="$(RebuildDependsOn)" Returns="@(CollectedBuildOutput)" />

<Target Name="Test"
DependsOnTargets="$(TestDependsOn)"
Condition=" '$(IsGraphBuild)' != 'true' ">
Expand Down

0 comments on commit 5ab9834

Please sign in to comment.