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

Fix double build Fixes #5830 #5838

Merged
merged 3 commits into from
Nov 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/Tasks/Microsoft.Common.CurrentVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1604,11 +1604,33 @@ Copyright (C) Microsoft Corporation. All rights reserved.
and the mechanism here for selecting the best one can be skipped as an optimization.

We give this treatment to .vcxproj by default since no .vcxproj can target more
than one framework.
than one framework currently. The user must specify exactly one TargetFramework.

vcxproj files compile down to OS-specific binaries, either native or .NET. In the
_GetProjectReferenceTargetFrameworkProperties target of Microsoft.Common.CurrentVersion.targets,
SkipTargetFrameworkProperties is set to true for vcxproj to account for that.

This means we do not fill the Item _ProjectReferenceTargetFrameworkPossibilities or, by extension,
the AnnotatedProjects Item.

For single-targeted projects, we normally decorate the AnnotatedProjects Item with
UndefineProperties metadata specifying that TargetFramework should be undefined. Because it
isn't defined properly at that stage, however, this does not happen, and TargetFramework is
defined at this point in addition to having been defined globally. Currently, this is always
true for vcxproj.

MSBuild permits building the same project twice as long as it has different sets of global properties.
Because the TargetFramework global property is not being removed as expected by the multitargeting
part of MSBuild, the engine recognizes that there are differences and builds it twice. This can
become more noticeable if the projects build in parallel, since they could try to access the same
resources and conflict, failing the build. Note, however, that building the same project twice in
this way is always wrong even if it seems minor because they do not conflict, and the second build is
relatively fast.
-->
<ItemGroup>
<_MSBuildProjectReferenceExistent Condition="'%(_MSBuildProjectReferenceExistent.SkipGetTargetFrameworkProperties)' == '' and ('%(Extension)' == '.vcxproj' or '%(Extension)' == '.nativeproj')">
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
<UndefineProperties>%(_MSBuildProjectReferenceExistent.UndefineProperties);TargetFramework</UndefineProperties>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it took us so long to figure this out please comment this.

</_MSBuildProjectReferenceExistent>
</ItemGroup>

Expand Down