Skip to content

Commit

Permalink
Fix issue where Targets are not passed through (#216)
Browse files Browse the repository at this point in the history
When a user specifies the Targets metadata on a ProjectReference, they are not passed along to the MSBuild task.  Also added a unit test.

Fixes #214
  • Loading branch information
jeffkl authored Nov 12, 2020
1 parent 4119ad1 commit f4ada22
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Traversal.UnitTests/TraversalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,40 @@ public void IsUsingMicrosoftTraversalSdkSet()
usingMicrosoftTraversalSdk.ShouldBe("true", StringCompareShould.IgnoreCase);
}

[Theory]
[InlineData(null, "F15898EAC7F347EA9011A752F0F4B81C")]
[InlineData("Build", "F15898EAC7F347EA9011A752F0F4B81C")]
[InlineData("Target1", "7D37800C941546489A320E1B2C0480BC")]
public void ProjectReferenceCanSpecifyTargets(string targets, string expected)
{
ProjectCreator projectA = ProjectCreator.Create(
path: GetTempFile("ProjectA.csproj"))
.Target("Build")
.TaskMessage("F15898EAC7F347EA9011A752F0F4B81C", MessageImportance.High)
.Target("Target1")
.TaskMessage("7D37800C941546489A320E1B2C0480BC", MessageImportance.High)
.Save();

ProjectCreator
.Templates
.TraversalProject(
path: GetTempFile("dirs.proj"),
customAction: creator => creator.ItemProjectReference(projectA, metadata: new Dictionary<string, string>
{
["Targets"] = targets,
}))
.Save()
.TryBuild(out bool result, out BuildOutput buildOutput);

result.ShouldBeTrue();

buildOutput.Messages.High.ShouldBe(
new[]
{
expected,
});
}

[Theory]
[InlineData("Build")]
[InlineData("Clean")]
Expand Down
1 change: 1 addition & 0 deletions src/Traversal/Sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
SkipNonexistentProjects="$(SkipNonexistentProjects)"
SkipNonexistentTargets="$(SkipNonexistentTargets)"
StopOnFirstFailure="$(StopOnFirstFailure)"
Targets="%(ProjectReference.Targets)"
ContinueOnError="$(ContinueOnError)">
<Output TaskParameter="TargetOutputs" ItemName="CollectedBuildOutput" />
</MSBuild>
Expand Down

0 comments on commit f4ada22

Please sign in to comment.