Skip to content

Fix project build exclusion logic in the face of static graph#12425

Merged
mmitche merged 4 commits intodotnet:mainfrom
mmitche:target-reordering-and-fixes-for-skipping-builds
Feb 6, 2023
Merged

Fix project build exclusion logic in the face of static graph#12425
mmitche merged 4 commits intodotnet:mainfrom
mmitche:target-reordering-and-fixes-for-skipping-builds

Conversation

@mmitche
Copy link
Member

@mmitche mmitche commented Feb 3, 2023

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:

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.
@mmitche mmitche requested review from a team and tmat February 3, 2023 22:48
@mmitche
Copy link
Member Author

mmitche commented Feb 6, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mmitche mmitche merged commit 02980a6 into dotnet:main Feb 6, 2023
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