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

Add ability to skip projects dynamically in Traversal projects and Visual Studio solution files #439

Merged
merged 2 commits into from
Apr 26, 2023

Conversation

jeffkl
Copy link
Contributor

@jeffkl jeffkl commented Apr 26, 2023

This implements the ability to dynamically skip projects when building a Traversal project or Visual Studio solution file. Users need to implement a target in Directory.Build.targets, the project itself, or some other import:

This example skips VSIX projects when building with dotnet build:

<Target Name="ShouldSkipProject" Returns="@(ProjectToSkip)">
  <ItemGroup Condition="'$(MSBuildRuntimeType)' == 'Core'">
    <!-- Skip building Visual Studio Extension (VSIX) projects if the user is building with dotnet build since its only supported to build those projects with MSBuild.exe -->
    <ProjectToSkip Include="$(MSBuildProjectFullPath)"
                   Message="Visual Studio Extension (VSIX) projects cannot be built with dotnet.exe and require you to use msbuild.exe or Visual Studio."
                   Condition="'$(VsSDKVersion)' != ''" />
  </ItemGroup>
</Target>

Users can also now extend Visual Studio solution file builds with Microsoft.Build.Traversal to get the same functionality. To do this, they must create a Directory.Solution.props and Directory.Solution.targets next to the solution file:

Directory.Solution.props:

<Project>
  <Import Project="Microsoft.Build.Traversal" Project="Sdk.props" />
</Project>

Directory.Solution.targets:

<Project>
  <Import Project="Microsoft.Build.Traversal" Project="Sdk.targets" />
</Project>

This gives them the ability to dynamically skip projects in the same way.

@jeffkl jeffkl self-assigned this Apr 26, 2023
@avivanoff
Copy link

@jeffkl, this looks like a breaking change when upgrading to 4.0.0 as it requires defining a ShouldSkipProject target even if you do not want to skip anything. Why not define an empty ShouldSkipProject target in the SDK?

@jeffkl
Copy link
Contributor Author

jeffkl commented May 15, 2023

@avivanoff the target that is called is in the projects referenced by Traversal which do not import Traversal, so Traversal cannot inject the target. But the MSBuild call should pass SkipNonExistingTargets so if the target does not exist you don't get an error and the project is not skipped.

ed27e69#diff-8a55a07e0ced81492f6e4a15a3f60dda3917fdf5d11c11754d61f705ea3fa272R271

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants