microsoft / microsoft/MSBuildSdks
[Traversal] Filtering projects solution files without kicking off evaluations
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 508
- Forks
- 94
- Avg merge
- 6h 40m
- Merged PRs (30d)
- 2
Description
The new filter projects in solution files feature in Microsoft.Build.Traversal is phenomenal. I noticed that by default, it still kicks off evaluations for the projects in order to then invoke the custom ShouldSkipProject target. In my situation, I don't want to even trigger evaluations (and with also not trigger msbuild sdk resolver events). I was able to make that work with the following code:
Directory.Solution.targets
<Project>
<Import Sdk="Microsoft.Build.Traversal" Project="Sdk.targets" />
<!-- Overwrite target from Traversal Sdk.targets. -->
<Target Name="GetProjectsToSkip">
<ItemGroup>
<ProjectToSkip Include="@(ProjectReference)"
Message=""
Condition="$([System.String]::new('%(ProjectReference.Identity)').EndsWith('.Tests.csproj'))"
OriginalItemSpec="%(Identity)" />
</ItemGroup>
</Target>
</Project>
Unfortunately this only works with normal restore and not static graph based restore: https://github.com/microsoft/MSBuildSdks/issues/521
Should we document this option? From my perspective, while this is a static mechanism to filter out projects, it's the only correct way as it doesn't even trigger evaluations of filtered out projects.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review Directory.Solution.targets and the Microsoft.Build.Traversal Sdk.targets implementation, then compare the normal restore behavior with the static graph limitation described in issue 521. Document the GetProjectsToSkip override for filtering projects before evaluation, including that it currently applies only to normal restore.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- build-system
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100