-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't use Targets* helper properties in libs (#64500)
* Don't use Targets* helper properties in libs projs This change makes it possible to migrate 200+ (ref+src) projects to use TargetFramework instead of TargetFrameworks which avoids the additional outer build evaluation and invocation which ultimately makes the overall build faster. Targets* properties (i.e. TargetsWindows, TargetsAnyOS, TargetsUnix, etc.) rely on the TargetFramework property which usually are set inside a project. The TargetFramework property is only available before a project specifies it if it's explicitly set in a props file or if the project is cross-targeting and the outer-build dispatches into the inner-build. During the dispatch, the TargetFramework property is passed in as a global property. Until now that behavior wasn't a problem because every libraries project cross-targeted (by setting the TargetFrameworks property) even though many only include a single TargetFramework (i.e. NetCoreAppCurrent). To allow projects to use the TargetFramework property instead of TargetFrameworks, the Targets* helper properties can't be calculated anymore early in a props file as the TargetFramework property isn't set at that time. In general, the guidance by the SDK/msbuild team is to not read from the TargetFramework property before the project sets it (in a property group). That effectively means that the TargetFramework property shouldn't be used in props files at all. Therefore these helper properties can't be used anymore for property conditions and I'm replacing their usage with TargetPlatformIdentifier comparisons for both properties and items. In nearly all cases, the Targets* helper properties can be replaced with TargetPlatformIdentifier checks on items and in the few cases where TargetsUnix or TargetsLinux marks multiple tfms as compatible, the exact tfms must be used instead for the TargetPlatformIdentifier comparison. Whenever a project needs to condition properties on the platform, I'm first setting the TargetPlatformIdentifier the same way the SDK sets it so that the SDK later doesn't need to set it again to avoid the additional expensive msbuild function call. * Use TargetFramework singular to avoid outer builds Use TargetFramework instead of TargetFrameworks property whenever a projects only targets a single target framework. This avoid unnecessary outer builds and evaluations and makes the build faster.
- Loading branch information
1 parent
55884ce
commit 20e8f90
Showing
349 changed files
with
931 additions
and
924 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
<Project> | ||
|
||
<Import Project="$(MSBuildThisDirectory)targetframeworksuffix.props" Condition="'$(DesignTimeBuild)' == 'true'" /> | ||
<PropertyGroup> | ||
<TargetPlatformSupported>true</TargetPlatformSupported> | ||
<TargetPlatformVersionSupported>true</TargetPlatformVersionSupported> | ||
|
||
<!-- Value of 0.0 produces versionless SupportedOSPlatform attribute. | ||
This is required for platforms not expected to have a version, | ||
and we currently omit the version for all platforms. --> | ||
<SupportedOSPlatformVersion>0.0</SupportedOSPlatformVersion> | ||
|
||
<!-- Disable setting a default Windows platform for .NETStandard and .NET Framework libraries. | ||
This ensures that the TargetPlatformIdentifier property is empty for non .NETCoreApp tfms. --> | ||
<_EnableDefaultWindowsPlatform>false</_EnableDefaultWindowsPlatform> | ||
<_targetPlatformIdentifier Condition="$(TargetFramework.Contains('-'))">$(TargetFramework.SubString($([MSBuild]::Add($(TargetFramework.IndexOf('-')), 1))))</_targetPlatformIdentifier> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(_targetPlatformIdentifier)' != '' and '$(_targetPlatformIdentifier)' != 'windows'"> | ||
<TargetPlatformVersion>1.0</TargetPlatformVersion> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project> | ||
|
||
<!-- Uses the Microsoft.DotNet.Build.Tasks.TargetFramework package to filter out target frameworks from ProjectReferences. --> | ||
<PropertyGroup Condition="'$(FilterTraversalProjectReferences)' == 'true'"> | ||
<BuildDependsOn>$(BuildDependsOn);ResolveP2PReferences</BuildDependsOn> | ||
<CleanDependsOn>$(CleanDependsOn);ResolveP2PReferences</CleanDependsOn> | ||
<RebuildDependsOn>$(RebuildDependsOn);ResolveP2PReferences</RebuildDependsOn> | ||
<TestDependsOn>$(TestDependsOn);ResolveP2PReferences</TestDependsOn> | ||
<VSTestDependsOn>$(VSTestDependsOn);ResolveP2PReferences</VSTestDependsOn> | ||
<PackDependsOn>$(PackDependsOn);ResolveP2PReferences</PackDependsOn> | ||
<PublishDependsOn>$(PublishDependsOn);ResolveP2PReferences</PublishDependsOn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(FilterTraversalProjectReferences)' == 'true'"> | ||
<ProjectReference Update="@(ProjectReference)" SkipGetTargetFrameworkProperties="false" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.