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: #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.
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
ShouldSkipProjecttarget. 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
Unfortunately this only works with normal restore and not static graph based restore: #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.