diff options
author | Viktor Hofer <viktor.hofer@microsoft.com> | 2022-02-12 15:07:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-12 15:07:16 +0300 |
commit | 20e8f905d05f2d8f390d0e2ef10f1a4a1289967c (patch) | |
tree | d1e2b24f597c5a19cff682e2c18b2fa71e1dfbde /eng | |
parent | 55884ce98580d4aa965d1717a62039a4b6d5033b (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')
-rw-r--r-- | eng/BeforeTargetFrameworkInference.targets | 19 | ||||
-rw-r--r-- | eng/TraversalSdk.AfterTargets.targets | 18 | ||||
-rw-r--r-- | eng/Version.Details.xml | 4 | ||||
-rw-r--r-- | eng/Versions.props | 2 | ||||
-rw-r--r-- | eng/packaging.targets | 6 | ||||
-rw-r--r-- | eng/targetframeworksuffix.props | 101 | ||||
-rw-r--r-- | eng/testing/tests.props | 4 | ||||
-rw-r--r-- | eng/versioning.targets | 26 |
8 files changed, 59 insertions, 121 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> diff --git a/eng/TraversalSdk.AfterTargets.targets b/eng/TraversalSdk.AfterTargets.targets new file mode 100644 index 00000000000..f88c48dc867 --- /dev/null +++ b/eng/TraversalSdk.AfterTargets.targets @@ -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>
\ No newline at end of file diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index ae6fdbb5972..05a44e0bf9d 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -102,9 +102,9 @@ <Uri>https://github.com/dotnet/arcade</Uri> <Sha>78eaf78761027d225030be2b28aaf4e8bf392929</Sha> </Dependency> - <Dependency Name="Microsoft.DotNet.Build.Tasks.TargetFramework" Version="7.0.0-beta.22110.7"> + <Dependency Name="Microsoft.DotNet.Build.Tasks.TargetFramework" Version="7.0.0-beta.22111.10"> <Uri>https://github.com/dotnet/arcade</Uri> - <Sha>78eaf78761027d225030be2b28aaf4e8bf392929</Sha> + <Sha>ff6cc4e9c3eef575f62a33a642ca80e79d27c9bb</Sha> </Dependency> <Dependency Name="Microsoft.DotNet.RemoteExecutor" Version="7.0.0-beta.22110.7"> <Uri>https://github.com/dotnet/arcade</Uri> diff --git a/eng/Versions.props b/eng/Versions.props index e43cb18f09a..3c0663f6dd1 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -67,7 +67,7 @@ <MicrosoftDotNetBuildTasksArchivesVersion>7.0.0-beta.22110.7</MicrosoftDotNetBuildTasksArchivesVersion> <MicrosoftDotNetBuildTasksInstallersVersion>7.0.0-beta.22110.7</MicrosoftDotNetBuildTasksInstallersVersion> <MicrosoftDotNetBuildTasksPackagingVersion>7.0.0-beta.22110.7</MicrosoftDotNetBuildTasksPackagingVersion> - <MicrosoftDotNetBuildTasksTargetFrameworkVersion>7.0.0-beta.22110.7</MicrosoftDotNetBuildTasksTargetFrameworkVersion> + <MicrosoftDotNetBuildTasksTargetFrameworkVersion>7.0.0-beta.22111.10</MicrosoftDotNetBuildTasksTargetFrameworkVersion> <MicrosoftDotNetBuildTasksTemplatingVersion>7.0.0-beta.22110.7</MicrosoftDotNetBuildTasksTemplatingVersion> <MicrosoftDotNetBuildTasksWorkloadsPackageVersion>7.0.0-beta.22110.7</MicrosoftDotNetBuildTasksWorkloadsPackageVersion> <MicrosoftDotNetRemoteExecutorVersion>7.0.0-beta.22110.7</MicrosoftDotNetRemoteExecutorVersion> diff --git a/eng/packaging.targets b/eng/packaging.targets index e705b4e7110..fd2568f5d30 100644 --- a/eng/packaging.targets +++ b/eng/packaging.targets @@ -10,9 +10,9 @@ <PackDependsOn>AddNETStandardCompatErrorFileForPackaging;IncludeAnalyzersInPackage;$(PackDependsOn)</PackDependsOn> <BeforePack>AddNETStandardCompatErrorFileForPackaging;IncludeAnalyzersInPackage;$(BeforePack)</BeforePack> <TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);AddRuntimeSpecificFilesToPackage;IncludeProjectReferencesWithPackAttributeInPackage</TargetsForTfmSpecificContentInPackage> - <IncludeBuildOutput Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(TargetPlatformIdentifier)' != ''">false</IncludeBuildOutput> + <IncludeBuildOutput Condition="'$(TargetPlatformIdentifier)' != ''">false</IncludeBuildOutput> <!-- Don't include target platform specific dependencies, since we use the target platform to represent RIDs instead --> - <SuppressDependenciesWhenPacking Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(TargetPlatformIdentifier)' != ''">true</SuppressDependenciesWhenPacking> + <SuppressDependenciesWhenPacking Condition="'$(TargetPlatformIdentifier)' != ''">true</SuppressDependenciesWhenPacking> <PackageDesignerMarkerFile>$(MSBuildThisFileDirectory)useSharedDesignerContext.txt</PackageDesignerMarkerFile> <!-- Generate packages for rid specific projects or for allconfigurations during build. --> <!-- A package isn't generated if in servicing or in runtimelab. Intended to be overridden at project level. --> @@ -101,7 +101,7 @@ DocumentationProjectOutputGroup; SatelliteDllsProjectOutputGroup; $(TargetsForTfmSpecificBuildOutput)" - Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(TargetPlatformIdentifier)' != ''"> + Condition="'$(TargetPlatformIdentifier)' != ''"> <PropertyGroup> <RuntimeSymbolPath>$(TargetDir)$(TargetName).pdb</RuntimeSymbolPath> <_packageTargetRuntime>$(TargetPlatformIdentifier.ToLowerInvariant().Replace('windows', 'win'))</_packageTargetRuntime> diff --git a/eng/targetframeworksuffix.props b/eng/targetframeworksuffix.props deleted file mode 100644 index f7074fe3e19..00000000000 --- a/eng/targetframeworksuffix.props +++ /dev/null @@ -1,101 +0,0 @@ -<Project> - - <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> - <TargetPlatformIdentifier Condition="$(TargetFramework.Contains('-'))">$(TargetFramework.SubString($([MSBuild]::Add($(TargetFramework.IndexOf('-')), 1))))</TargetPlatformIdentifier> - </PropertyGroup> - - <PropertyGroup Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetPlatformIdentifier)' != 'windows'"> - <TargetPlatformVersion>1.0</TargetPlatformVersion> - </PropertyGroup> - - <Choose> - <When Condition="'$(TargetPlatformIdentifier)' == 'windows'"> - <PropertyGroup> - <TargetsWindows>true</TargetsWindows> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == 'Unix'"> - <PropertyGroup> - <TargetsUnix>true</TargetsUnix> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == 'Linux'"> - <PropertyGroup> - <TargetsUnix>true</TargetsUnix> - <TargetsLinux>true</TargetsLinux> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == 'Android'"> - <PropertyGroup> - <TargetsUnix>true</TargetsUnix> - <TargetsLinux>true</TargetsLinux> - <TargetsAndroid>true</TargetsAndroid> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == 'OSX'"> - <PropertyGroup> - <TargetsUnix>true</TargetsUnix> - <TargetsOSX>true</TargetsOSX> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == 'MacCatalyst'"> - <PropertyGroup> - <TargetsUnix>true</TargetsUnix> - <TargetsMacCatalyst>true</TargetsMacCatalyst> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == 'tvOS'"> - <PropertyGroup> - <TargetsUnix>true</TargetsUnix> - <TargetstvOS>true</TargetstvOS> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == 'iOS'"> - <PropertyGroup> - <TargetsUnix>true</TargetsUnix> - <TargetsiOS>true</TargetsiOS> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == 'FreeBSD'"> - <PropertyGroup> - <TargetsUnix>true</TargetsUnix> - <TargetsFreeBSD>true</TargetsFreeBSD> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == 'NetBSD'"> - <PropertyGroup> - <TargetsUnix>true</TargetsUnix> - <TargetsNetBSD>true</TargetsNetBSD> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == 'illumos'"> - <PropertyGroup> - <TargetsUnix>true</TargetsUnix> - <Targetsillumos>true</Targetsillumos> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == 'Solaris'"> - <PropertyGroup> - <TargetsUnix>true</TargetsUnix> - <TargetsSolaris>true</TargetsSolaris> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == 'Browser'"> - <PropertyGroup> - <TargetsBrowser>true</TargetsBrowser> - </PropertyGroup> - </When> - <When Condition="'$(TargetPlatformIdentifier)' == ''"> - <PropertyGroup> - <TargetsAnyOS>true</TargetsAnyOS> - </PropertyGroup> - </When> - </Choose> -</Project> diff --git a/eng/testing/tests.props b/eng/testing/tests.props index f23f4cc62e9..e91ec1bbcf0 100644 --- a/eng/testing/tests.props +++ b/eng/testing/tests.props @@ -34,8 +34,8 @@ <!-- Provide runtime options to Mono (interpreter, aot, debugging, etc) --> <ItemGroup Condition="'$(MonoEnvOptions)' != '' and '$(TargetsMobile)' != 'true'"> - <RunScriptCommands Condition="'$(TargetsWindows)' == 'true'" Include="set MONO_ENV_OPTIONS='$(MonoEnvOptions)'" /> - <RunScriptCommands Condition="'$(TargetsWindows)' != 'true'" Include="export MONO_ENV_OPTIONS='$(MonoEnvOptions)'" /> + <RunScriptCommands Condition="'$(TargetsWindows)' == 'true' or '$(TargetPlatformIdentifier)' == 'windows'" Include="set MONO_ENV_OPTIONS='$(MonoEnvOptions)'" /> + <RunScriptCommands Condition="'$(TargetsWindows)' != 'true' and '$(TargetPlatformIdentifier)' != 'windows'" Include="export MONO_ENV_OPTIONS='$(MonoEnvOptions)'" /> </ItemGroup> <ItemGroup Condition="'$(TestRunRequiresLiveRefPack)' == 'true'"> diff --git a/eng/versioning.targets b/eng/versioning.targets index 4dacec01a86..37e9eba03cd 100644 --- a/eng/versioning.targets +++ b/eng/versioning.targets @@ -25,8 +25,8 @@ </AssemblyMetadata> </ItemGroup> - <PropertyGroup Condition="'$(TargetsAnyOS)' == 'true' and !$(TargetFrameworks.Contains('$(TargetFramework)-Browser'))"> - <CrossPlatformAndHasNoBrowserTarget>true</CrossPlatformAndHasNoBrowserTarget> + <PropertyGroup Condition="'$(TargetPlatformIdentifier)' == '' and !$(TargetFrameworks.Contains('$(TargetFramework)-Browser'))"> + <CrossPlatformAndHasNoBrowserTarget>true</CrossPlatformAndHasNoBrowserTarget> </PropertyGroup> <!-- Enables warnings for Android, iOS, tvOS and macCatalyst for all builds --> @@ -38,16 +38,18 @@ </ItemGroup> <!-- Enables browser warnings for cross platform or Browser targeted builds --> - <ItemGroup Condition="('$(TargetsBrowser)' == 'true' or '$(CrossPlatformAndHasNoBrowserTarget)' == 'true') and '$(IsTestProject)' != 'true'"> + <ItemGroup Condition="('$(TargetPlatformIdentifier)' == 'Browser' or '$(CrossPlatformAndHasNoBrowserTarget)' == 'true') and '$(IsTestProject)' != 'true'"> <SupportedPlatform Include="browser"/> </ItemGroup> <!-- Add target platforms into MSBuild SupportedPlatform list --> - <ItemGroup Condition="'$(TargetsAnyOS)' != 'true' and '$(IsTestProject)' != 'true'"> - <SupportedPlatform Condition="'$(Targetsillumos)' == 'true'" Include="illumos"/> - <SupportedPlatform Condition="'$(TargetsSolaris)' == 'true'" Include="Solaris"/> - <SupportedPlatform Condition="'$(TargetstvOS)' == 'true'" Include="tvOS"/> - <SupportedPlatform Condition="'$(TargetsUnix)' == 'true'" Include="Unix"/> + <ItemGroup Condition="'$(IsTestProject)' != 'true'"> + <SupportedPlatform Condition="'$(TargetPlatformIdentifier)' == 'illumos'" Include="illumos" /> + <SupportedPlatform Condition="'$(TargetPlatformIdentifier)' == 'Solaris'" Include="Solaris" /> + <SupportedPlatform Condition="'$(TargetPlatformIdentifier)' == 'tvOS'" Include="tvOS" /> + <SupportedPlatform Condition="'$(TargetPlatformIdentifier)' != '' and + '$(TargetPlatformIdentifier)' != 'Browser' and + '$(TargetPlatformIdentifier)' != 'windows'" Include="Unix" /> </ItemGroup> <!-- Adds UnsupportedOSPlatform and SupportedOSPlatform attributes to the assembly when: @@ -55,8 +57,10 @@ * This is a cross-platform target * The build isn't targeting .NET Framework --> - <Target Name="AddOSPlatformAttributes" BeforeTargets="GenerateAssemblyInfo" AfterTargets="PrepareForBuild" - Condition="'$(TargetsAnyOS)' == 'true' and '$(IsTestProject)' != 'true' and '$(TargetFrameworkIdentifier)' != '.NETFramework'"> + <Target Name="AddOSPlatformAttributes" + BeforeTargets="GenerateAssemblyInfo" + AfterTargets="PrepareForBuild" + Condition="'$(TargetPlatformIdentifier)' == '' and '$(IsTestProject)' != 'true' and '$(TargetFrameworkIdentifier)' != '.NETFramework'"> <!-- Defensively de-dupe the values --> <ItemGroup> <_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" /> @@ -85,7 +89,7 @@ </Target> <!-- Add PlatformNeutralAssembly property for targeted builds of cross platform assemblies --> - <ItemGroup Condition="'$(TargetsAnyOS)' != 'true' and '$(IsTestProject)' != 'true' and '@(SupportedOSPlatforms)' == ''"> + <ItemGroup Condition="'$(TargetPlatformIdentifier)' != '' and '$(IsTestProject)' != 'true' and '@(SupportedOSPlatforms)' == ''"> <CompilerVisibleProperty Include="PlatformNeutralAssembly" /> </ItemGroup> |