Skip to content

Commit

Permalink
Fix double build Fixes #5830 (#5838)
Browse files Browse the repository at this point in the history
* Undefine TargetFramework if skipping TargetFramework

Fixes #5830. See explanation there.
  • Loading branch information
Forgind authored Nov 13, 2020
1 parent 56ab634 commit 1954bb4
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Tasks/Microsoft.Common.CurrentVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1605,11 +1605,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>
</_MSBuildProjectReferenceExistent>
</ItemGroup>

Expand Down

0 comments on commit 1954bb4

Please sign in to comment.