Use targetPlatformMoniker for net5.0 and newer tfms (#43965)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Fri, 6 Nov 2020 03:54:19 +0000 (19:54 -0800)
committerGitHub <noreply@github.com>
Fri, 6 Nov 2020 03:54:19 +0000 (19:54 -0800)
* Use targetPlatformMoniker for net5.0 and newer tfms

* disabling analyzer, update version to 0.0, and use new format.

* update the targetFramework.sdk

* removing supportedOS assembly level attribute

* fix linker errors and addressing feedback

* making _TargetFrameworkWithoutPlatform as private

eng/BeforeTargetFrameworkInference.targets
eng/resolveContract.targets
eng/targetframeworksuffix.props
eng/versioning.targets
global.json
src/libraries/Directory.Build.props

index abef4c8..9360938 100644 (file)
@@ -3,17 +3,18 @@
   <PropertyGroup Condition="$(TargetFramework.Contains('-'))">
     <_OriginalTargetFramework>$(TargetFramework)</_OriginalTargetFramework>
     <TargetFrameworkSuffix>$(TargetFramework.SubString($([MSBuild]::Add($(TargetFramework.IndexOf('-')), 1))))</TargetFrameworkSuffix>
-    <TargetFramework>$(TargetFramework.SubString(0, $(TargetFramework.IndexOf('-'))))</TargetFramework>
+    <!-- Strip away the TargetPlatform during the build for frameworks older than net5.0 because the assets file does not know about the TargetPlatform -->
+    <TargetFramework>$([System.Text.RegularExpressions.Regex]::Replace('$(TargetFramework)', '$(TargetFrameworkPattern)', '${1}'))</TargetFramework>
   </PropertyGroup>
 
   <Import Project="$(MSBuildThisDirectory)targetframeworksuffix.props" Condition="'$(DesignTimeBuild)' == 'true'" />
 
   <PropertyGroup>
-    <IntermediateOutputPath>$([MSBuild]::NormalizeDirectory('$(BaseIntermediateOutputPath)', '$(TargetFramework)-$(TargetFrameworkSuffix)-$(Configuration)'))</IntermediateOutputPath>
-    <IntermediateOutputPath Condition="'$(TargetFrameworkSuffix)' == ''">$([MSBuild]::NormalizeDirectory('$(BaseIntermediateOutputPath)', '$(TargetFramework)-$(Configuration)'))</IntermediateOutputPath>
+    <IntermediateOutputPath>$([MSBuild]::NormalizeDirectory('$(BaseIntermediateOutputPath)', '$(TargetFramework)-$(Configuration)'))</IntermediateOutputPath>
+    <IntermediateOutputPath Condition="'$(TargetFrameworkSuffix)' != '' and !$(TargetFramework.Contains('-'))">$([MSBuild]::NormalizeDirectory('$(BaseIntermediateOutputPath)', '$(TargetFramework)-$(TargetFrameworkSuffix)-$(Configuration)'))</IntermediateOutputPath>
     <!-- setting the output paths -->
-    <OutputPath>$([MSBuild]::NormalizeDirectory('$(BaseOutputPath)', '$(TargetFramework)-$(TargetFrameworkSuffix)-$(Configuration)'))</OutputPath>
-    <OutputPath Condition="'$(TargetFrameworkSuffix)' == ''">$([MSBuild]::NormalizeDirectory('$(BaseOutputPath)', '$(TargetFramework)-$(Configuration)'))</OutputPath>
+    <OutputPath>$([MSBuild]::NormalizeDirectory('$(BaseOutputPath)', '$(TargetFramework)-$(Configuration)'))</OutputPath>
+    <OutputPath Condition="'$(TargetFrameworkSuffix)' != '' and !$(TargetFramework.Contains('-'))">$([MSBuild]::NormalizeDirectory('$(BaseOutputPath)', '$(TargetFramework)-$(TargetFrameworkSuffix)-$(Configuration)'))</OutputPath>
   </PropertyGroup>
 
 </Project>
index 6f4bb0e..0608475 100644 (file)
@@ -12,8 +12,8 @@
     <ContractAssemblyPath Condition="'$(ContractAssemblyPath)' == '' and
                                      '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
                                      $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '$(NETCoreAppCurrentVersion)'))">$(NetCoreAppCurrentRefPath)$(TargetFileName)</ContractAssemblyPath>
-    <ContractAssemblyPath Condition="'$(ContractAssemblyPath)' == ''">$([MSBuild]::NormalizePath('$(BaseOutputPath)', 'ref', '$(TargetFramework)-$(Configuration)', '$(TargetFileName)'))</ContractAssemblyPath>
-
+    <_TargetFrameworkWithoutPlatform>$([System.Text.RegularExpressions.Regex]::Replace('$(TargetFramework)', '(-[^;]+)', ''))</_TargetFrameworkWithoutPlatform>
+    <ContractAssemblyPath Condition="'$(ContractAssemblyPath)' == ''">$([MSBuild]::NormalizePath('$(BaseOutputPath)', 'ref', '$(_TargetFrameworkWithoutPlatform)-$(Configuration)', '$(TargetFileName)'))</ContractAssemblyPath>
     <!-- Disable API compat if the project doesn't have reference assembly -->
     <RunApiCompat Condition="'$(HasMatchingContract)' != 'true'">false</RunApiCompat>
   </PropertyGroup>
@@ -59,4 +59,4 @@
                                       ReferenceAssembly="" />
     </ItemGroup>
   </Target>
-</Project>
\ No newline at end of file
+</Project>
index 80443a1..2525ce9 100644 (file)
@@ -1,4 +1,16 @@
 <Project>
+  
+  <PropertyGroup>
+    <TargetPlatformSupported>true</TargetPlatformSupported>
+    <TargetPlatformVersionSupported>true</TargetPlatformVersionSupported>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(TargetFrameworkSuffix)' != '' and '$(TargetFrameworkSuffix)' != 'windows'">
+    <TargetPlatformIdentifier>$(TargetFrameworkSuffix)</TargetPlatformIdentifier>
+    <TargetPlatformVersion>0.0</TargetPlatformVersion>
+    <TargetPlatformMoniker>$(TargetFrameworkSuffix),Version=$(TargetPlatformVersion)</TargetPlatformMoniker>
+  </PropertyGroup>
+  
   <Choose>
     <When Condition="'$(TargetFrameworkSuffix)' == 'windows'">
       <PropertyGroup>
index 6178974..3177b48 100644 (file)
       WriteOnlyWhenDifferent="true" />
 
   </Target>
+
+  <!-- Removes specified assembly level attributes. https://github.com/dotnet/runtime/issues/44257-->
+  <Target Name="RemoveSupportedPlatformAssemblyLevelAttribute"
+          AfterTargets="GetAssemblyAttributes">
+    <ItemGroup>
+      <AssemblyAttribute Remove="System.Runtime.Versioning.SupportedOSPlatformAttribute" />
+      <AssemblyAttribute Remove="System.Runtime.Versioning.TargetPlatformAttribute" />
+    </ItemGroup>
+  </Target>
+
 </Project>
index 712486f..e74fc18 100644 (file)
@@ -12,7 +12,7 @@
     "python3": "3.7.1"
   },
   "msbuild-sdks": {
-    "Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk": "6.0.0-beta.20529.1",
+    "Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk": "6.0.0-beta.20554.1",
     "Microsoft.DotNet.Arcade.Sdk": "6.0.0-beta.20529.1",
     "Microsoft.DotNet.Build.Tasks.SharedFramework.Sdk": "6.0.0-beta.20529.1",
     "Microsoft.DotNet.Helix.Sdk": "6.0.0-beta.20529.1",
index 9e05e68..b48551a 100644 (file)
@@ -39,7 +39,7 @@
 
     <!-- Initialize BuildSettings from the individual properties. -->
     <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
-    <BuildTargetFramework Condition="'$(BuildTargetFramework)' == '' and '$(TargetFramework)' != ''">$(TargetFramework)</BuildTargetFramework>
+    <BuildTargetFramework Condition="'$(BuildTargetFramework)' == '' and '$(TargetFramework)' != ''">$([System.Text.RegularExpressions.Regex]::Replace('$(TargetFramework)', '(-[^;]+)', ''))</BuildTargetFramework>
     <!-- Build all .NET Framework configurations when net48 is passed in. This is for convenience. -->
     <AdditionalBuildTargetFrameworks Condition="'$(BuildTargetFramework)' == 'net48'">net45;net451;net452;net46;net461;net462;net47;net471;net472</AdditionalBuildTargetFrameworks>
     <AdditionalBuildTargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true' and '$(BuildAllProjects)' == 'true'">$(AdditionalBuildTargetFrameworks);netstandard2.0</AdditionalBuildTargetFrameworks>