Fix project build exclusion logic in the face of static graph#12425
Merged
mmitche merged 4 commits intodotnet:mainfrom Feb 6, 2023
Merged
Conversation
While working on filtering, I discovered that static graph and target filtering do not play nicely together. After some help from the msbuild team, the problem was identified. Arcade typically uses a series of empty targets that override standard targets (or its own) to avoid executing a project build or restore. Static graph, however, uses the existence of the _IsProjectRestoreSupported target, rather than its return value to determine whether restore is supported. This means that any excluded project still gets restored in static graph mode. The fix (or workaround, depending on how you look at it) for this is to set the NuGetRestoreTargets file to an empty stub early enough in the build (in the BeforeCommonTargets hook) so that this target is never loaded at all. This requires determining whether a build will be skipped earlier than we do today, in BeforeCommonTargets rather than in Sdk.targets. The code has been refactored so that we determine whether a build should be skipped in ExcludeFromBuild.BeforeCommonTargets.targets, which is imported in the BeforeCommonTargets files. I've also moved the import of these files earlier so that in cases where the BeforeCommonTargets SDK hook is **not** used (see dotnet#2676), we will still compute the exclusion properties early enough to import "Empty.targets". In that case, we also create the target.
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
MichaelSimons
approved these changes
Feb 6, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While working on filtering, I discovered that static graph and target filtering do not play nicely together. After some help from the msbuild team, the problem was identified. Arcade typically uses a series of empty targets that override standard targets (or its own) to avoid executing a project build or restore. Static graph, however, uses the existence of the _IsProjectRestoreSupported target, rather than its return value to determine whether restore is supported. This means that any excluded project still gets restored in static graph mode.
The fix (or workaround, depending on how you look at it) for this is to set the NuGetRestoreTargets file to an empty stub early enough in the build (in the BeforeCommonTargets hook) so that this target is never loaded at all. This requires determining whether a build will be skipped earlier than we do today, in BeforeCommonTargets rather than in Sdk.targets.
The code has been refactored so that we determine whether a build should be skipped in ExcludeFromBuild.BeforeCommonTargets.targets, which is imported in the BeforeCommonTargets files. I've also moved the import of these files earlier so that in cases where the BeforeCommonTargets SDK hook is not used (see #2676), we will still compute the exclusion properties early enough to import "Empty.targets". In that case, we also create the target.
To double check: