Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViktor Hofer <viktor.hofer@microsoft.com>2022-02-12 15:07:16 +0300
committerGitHub <noreply@github.com>2022-02-12 15:07:16 +0300
commit20e8f905d05f2d8f390d0e2ef10f1a4a1289967c (patch)
treed1e2b24f597c5a19cff682e2c18b2fa71e1dfbde /eng/BeforeTargetFrameworkInference.targets
parent55884ce98580d4aa965d1717a62039a4b6d5033b (diff)
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.
Diffstat (limited to 'eng/BeforeTargetFrameworkInference.targets')
-rw-r--r--eng/BeforeTargetFrameworkInference.targets19
1 files changed, 18 insertions, 1 deletions
diff --git a/eng/BeforeTargetFrameworkInference.targets b/eng/BeforeTargetFrameworkInference.targets
index 60b41284548..70de3444b58 100644
--- a/eng/BeforeTargetFrameworkInference.targets
+++ b/eng/BeforeTargetFrameworkInference.targets
@@ -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>