Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make skipping of unsupported projects off by default #449

Merged
merged 1 commit into from
May 30, 2023
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
4 changes: 2 additions & 2 deletions src/Traversal.UnitTests/SolutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public void SolutionsCanSkipProjects()
ProjectCreator.Templates.SolutionMetaproj(
TestRootPath,
new[] { projectA, projectB })
.Property("TraversalSkipUnsupportedProjects", bool.TrueString)
.TryBuild("Build", out bool result, out BuildOutput buildOutput, out IDictionary<string, TargetResult> targetOutputs);

result.ShouldBeTrue();

buildOutput.Messages.High.ShouldHaveSingleItem()
.ShouldContain("Project B is skipped!");
buildOutput.Messages.High.ShouldContain(i => i.Contains("Project B is skipped!"));

targetOutputs.TryGetValue("Build", out TargetResult buildTargetResult).ShouldBeTrue();

Expand Down
13 changes: 3 additions & 10 deletions src/Traversal.UnitTests/TraversalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,12 @@ public void TraversalsCanSkipProjects()

ProjectCreator.Templates
.TraversalProject(new string[] { projectA, projectB }, path: GetTempFile("dirs.proj"))
.Property("TraversalSkipUnsupportedProjects", bool.TrueString)
.TryBuild("Build", out bool result, out BuildOutput buildOutput, out IDictionary<string, TargetResult> targetOutputs);

result.ShouldBeTrue();

buildOutput.Messages.High.ShouldHaveSingleItem()
.ShouldContain("Project B is skipped!");
buildOutput.Messages.High.ShouldContain(i => i.Contains("Project B is skipped!"), buildOutput.GetConsoleLog());

targetOutputs.TryGetValue("Build", out TargetResult buildTargetResult).ShouldBeTrue();

Expand Down Expand Up @@ -472,14 +472,7 @@ public void TraversalTargetsRun(string target)

result.ShouldBeTrue(buildOutput.GetConsoleLog());

buildOutput.Messages.High.ShouldBe(
new[]
{
"BF0C6E1044514FE3AE4B78EC308D6F45",
"40869F4000B44D75A52AB305F24E0FDB",
},
ignoreOrder: true,
buildOutput.GetConsoleLog());
buildOutput.Messages.High.ShouldContain(i => string.Equals(i, "BF0C6E1044514FE3AE4B78EC308D6F45") || string.Equals(i, "40869F4000B44D75A52AB305F24E0FDB"), buildOutput.GetConsoleLog());
}

[Theory]
Expand Down
12 changes: 11 additions & 1 deletion src/Traversal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ This allows you to pass MSBuild global properties to skip a particular project:
msbuild /Property:DoNotBuildWebApp=true
```

Another method is to add a `ShouldSkipProject` target to your `Directory.Build.targets`. Use the target below as a template:
Another method is to enable skipping of unsupported projects by setting the `TraversalSkipUnsupportedProjects` MSBuild property in `Directory.Build.props`:

```xml
<PropertyGroup>
<TraversalSkipUnsupportedProjects>true</TraversalSkipUnsupportedProjects>
</PropertyGroup>
```

Then you define a `ShouldSkipProject` target to your `Directory.Build.targets` that skips projects if they are unsupported. Use the target below as a template:
```xml
<Target Name="ShouldSkipProject" Returns="@(ProjectToSkip)">
<ItemGroup>
Expand Down Expand Up @@ -89,6 +96,9 @@ in the same folder of any solution with the following contents:
Directory.Solution.props:
```xml
<Project>
<PropertyGroup>
<TraversalSkipUnsupportedProjects>true</TraversalSkipUnsupportedProjects>
</PropertyGroup>
<Import Project="Microsoft.Build.Traversal" Project="Sdk.props" />
</Project>
```
Expand Down
2 changes: 1 addition & 1 deletion src/Traversal/Sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<Target Name="SkipProjects"
DependsOnTargets="GetProjectsToSkip"
Condition="'$(SkipProjects)' != 'false'">
Condition="'$(TraversalSkipUnsupportedProjects)' == 'true'">
<ItemGroup>
<_NonExistentProjectToSkip Include="@(ProjectToSkip)" Condition="!Exists('%(ProjectToSkip.Identity)')"/>
<ProjectReference Remove="%(ProjectToSkip.OriginalItemSpec)" />
Expand Down
2 changes: 1 addition & 1 deletion src/Traversal/version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"inherit": true,
"version": "4.0"
"version": "4.1"
}