Skip to content

Commit 5c3c690

Browse files
authored
Use targetPlatformMoniker for net5.0 and newer tfms (#43965)
* 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
1 parent 5aaf0c1 commit 5c3c690

6 files changed

+33
-10
lines changed

eng/BeforeTargetFrameworkInference.targets

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
<PropertyGroup Condition="$(TargetFramework.Contains('-'))">
44
<_OriginalTargetFramework>$(TargetFramework)</_OriginalTargetFramework>
55
<TargetFrameworkSuffix>$(TargetFramework.SubString($([MSBuild]::Add($(TargetFramework.IndexOf('-')), 1))))</TargetFrameworkSuffix>
6-
<TargetFramework>$(TargetFramework.SubString(0, $(TargetFramework.IndexOf('-'))))</TargetFramework>
6+
<!-- Strip away the TargetPlatform during the build for frameworks older than net5.0 because the assets file does not know about the TargetPlatform -->
7+
<TargetFramework>$([System.Text.RegularExpressions.Regex]::Replace('$(TargetFramework)', '$(TargetFrameworkPattern)', '${1}'))</TargetFramework>
78
</PropertyGroup>
89

910
<Import Project="$(MSBuildThisDirectory)targetframeworksuffix.props" Condition="'$(DesignTimeBuild)' == 'true'" />
1011

1112
<PropertyGroup>
12-
<IntermediateOutputPath>$([MSBuild]::NormalizeDirectory('$(BaseIntermediateOutputPath)', '$(TargetFramework)-$(TargetFrameworkSuffix)-$(Configuration)'))</IntermediateOutputPath>
13-
<IntermediateOutputPath Condition="'$(TargetFrameworkSuffix)' == ''">$([MSBuild]::NormalizeDirectory('$(BaseIntermediateOutputPath)', '$(TargetFramework)-$(Configuration)'))</IntermediateOutputPath>
13+
<IntermediateOutputPath>$([MSBuild]::NormalizeDirectory('$(BaseIntermediateOutputPath)', '$(TargetFramework)-$(Configuration)'))</IntermediateOutputPath>
14+
<IntermediateOutputPath Condition="'$(TargetFrameworkSuffix)' != '' and !$(TargetFramework.Contains('-'))">$([MSBuild]::NormalizeDirectory('$(BaseIntermediateOutputPath)', '$(TargetFramework)-$(TargetFrameworkSuffix)-$(Configuration)'))</IntermediateOutputPath>
1415
<!-- setting the output paths -->
15-
<OutputPath>$([MSBuild]::NormalizeDirectory('$(BaseOutputPath)', '$(TargetFramework)-$(TargetFrameworkSuffix)-$(Configuration)'))</OutputPath>
16-
<OutputPath Condition="'$(TargetFrameworkSuffix)' == ''">$([MSBuild]::NormalizeDirectory('$(BaseOutputPath)', '$(TargetFramework)-$(Configuration)'))</OutputPath>
16+
<OutputPath>$([MSBuild]::NormalizeDirectory('$(BaseOutputPath)', '$(TargetFramework)-$(Configuration)'))</OutputPath>
17+
<OutputPath Condition="'$(TargetFrameworkSuffix)' != '' and !$(TargetFramework.Contains('-'))">$([MSBuild]::NormalizeDirectory('$(BaseOutputPath)', '$(TargetFramework)-$(TargetFrameworkSuffix)-$(Configuration)'))</OutputPath>
1718
</PropertyGroup>
1819

1920
</Project>

eng/resolveContract.targets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<ContractAssemblyPath Condition="'$(ContractAssemblyPath)' == '' and
1313
'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
1414
$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '$(NETCoreAppCurrentVersion)'))">$(NetCoreAppCurrentRefPath)$(TargetFileName)</ContractAssemblyPath>
15-
<ContractAssemblyPath Condition="'$(ContractAssemblyPath)' == ''">$([MSBuild]::NormalizePath('$(BaseOutputPath)', 'ref', '$(TargetFramework)-$(Configuration)', '$(TargetFileName)'))</ContractAssemblyPath>
16-
15+
<_TargetFrameworkWithoutPlatform>$([System.Text.RegularExpressions.Regex]::Replace('$(TargetFramework)', '(-[^;]+)', ''))</_TargetFrameworkWithoutPlatform>
16+
<ContractAssemblyPath Condition="'$(ContractAssemblyPath)' == ''">$([MSBuild]::NormalizePath('$(BaseOutputPath)', 'ref', '$(_TargetFrameworkWithoutPlatform)-$(Configuration)', '$(TargetFileName)'))</ContractAssemblyPath>
1717
<!-- Disable API compat if the project doesn't have reference assembly -->
1818
<RunApiCompat Condition="'$(HasMatchingContract)' != 'true'">false</RunApiCompat>
1919
</PropertyGroup>
@@ -59,4 +59,4 @@
5959
ReferenceAssembly="" />
6060
</ItemGroup>
6161
</Target>
62-
</Project>
62+
</Project>

eng/targetframeworksuffix.props

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
<Project>
2+
3+
<PropertyGroup>
4+
<TargetPlatformSupported>true</TargetPlatformSupported>
5+
<TargetPlatformVersionSupported>true</TargetPlatformVersionSupported>
6+
</PropertyGroup>
7+
8+
<PropertyGroup Condition="'$(TargetFrameworkSuffix)' != '' and '$(TargetFrameworkSuffix)' != 'windows'">
9+
<TargetPlatformIdentifier>$(TargetFrameworkSuffix)</TargetPlatformIdentifier>
10+
<TargetPlatformVersion>0.0</TargetPlatformVersion>
11+
<TargetPlatformMoniker>$(TargetFrameworkSuffix),Version=$(TargetPlatformVersion)</TargetPlatformMoniker>
12+
</PropertyGroup>
13+
214
<Choose>
315
<When Condition="'$(TargetFrameworkSuffix)' == 'windows'">
416
<PropertyGroup>

eng/versioning.targets

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,14 @@
155155
WriteOnlyWhenDifferent="true" />
156156

157157
</Target>
158+
159+
<!-- Removes specified assembly level attributes. https://github.com/dotnet/runtime/issues/44257-->
160+
<Target Name="RemoveSupportedPlatformAssemblyLevelAttribute"
161+
AfterTargets="GetAssemblyAttributes">
162+
<ItemGroup>
163+
<AssemblyAttribute Remove="System.Runtime.Versioning.SupportedOSPlatformAttribute" />
164+
<AssemblyAttribute Remove="System.Runtime.Versioning.TargetPlatformAttribute" />
165+
</ItemGroup>
166+
</Target>
167+
158168
</Project>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"python3": "3.7.1"
1313
},
1414
"msbuild-sdks": {
15-
"Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk": "6.0.0-beta.20529.1",
15+
"Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk": "6.0.0-beta.20554.1",
1616
"Microsoft.DotNet.Arcade.Sdk": "6.0.0-beta.20529.1",
1717
"Microsoft.DotNet.Build.Tasks.SharedFramework.Sdk": "6.0.0-beta.20529.1",
1818
"Microsoft.DotNet.Helix.Sdk": "6.0.0-beta.20529.1",

src/libraries/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
<!-- Initialize BuildSettings from the individual properties. -->
4141
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
42-
<BuildTargetFramework Condition="'$(BuildTargetFramework)' == '' and '$(TargetFramework)' != ''">$(TargetFramework)</BuildTargetFramework>
42+
<BuildTargetFramework Condition="'$(BuildTargetFramework)' == '' and '$(TargetFramework)' != ''">$([System.Text.RegularExpressions.Regex]::Replace('$(TargetFramework)', '(-[^;]+)', ''))</BuildTargetFramework>
4343
<!-- Build all .NET Framework configurations when net48 is passed in. This is for convenience. -->
4444
<AdditionalBuildTargetFrameworks Condition="'$(BuildTargetFramework)' == 'net48'">net45;net451;net452;net46;net461;net462;net47;net471;net472</AdditionalBuildTargetFrameworks>
4545
<AdditionalBuildTargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true' and '$(BuildAllProjects)' == 'true'">$(AdditionalBuildTargetFrameworks);netstandard2.0</AdditionalBuildTargetFrameworks>

0 commit comments

Comments
 (0)