Skip to content

[Traversal] Filtering projects solution files without kicking off evaluations #522

Open

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: #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions