Skip to content

Commit 293d472

Browse files
authored
Generate targets files that throws for unsupported netstandard applicable tfms (#53244)
* Generate targets files that throw for unsupported NS tfm For S.D.Common, S.Speech and S.Sec.Crypto.Pkcs we manually added a targets file to mark the .NETStandard asset as not applicable. This was done to allow defining a minimum supported .NETCoreApp version, even though a compatible .NETStandard asset is available. This commit automatically generates that targets file based on items.
1 parent f584c74 commit 293d472

File tree

10 files changed

+41
-32
lines changed

10 files changed

+41
-32
lines changed

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@
258258
<GeneratePackage Condition="(('$(PreReleaseVersionLabel)' == 'servicing' or
259259
'$(GitHubRepositoryName)' == 'runtimelab') and
260260
'$(MSBuildProjectExtension)' != '.sfxproj')">false</GeneratePackage>
261+
<PlaceholderFile>$(RepositoryEngineeringDir)_._</PlaceholderFile>
261262
</PropertyGroup>
262263

263264
<!-- Language configuration -->

Directory.Build.targets

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<PackageDescription Condition="'$(PackageDescription)' == '' and '$(UseRuntimePackageDisclaimer)' == 'true'">$(RuntimePackageDisclaimer)</PackageDescription>
5555
<!-- Keep in sync as required by the Packaging SDK in Arcade. -->
5656
<Description>$(PackageDescription)</Description>
57+
<BeforePack>$(BeforePack);AddNETStandardCompatErrorFileForPackaging</BeforePack>
5758
</PropertyGroup>
5859

5960
<!-- Remove when https://github.com/NuGet/Home/issues/10405 is implemented and consumed. -->
@@ -70,4 +71,39 @@
7071
<PackDependsOn />
7172
</PropertyGroup>
7273
</Target>
74+
75+
<!-- Add targets file that marks a .NETStandard applicable tfm as unsupported. -->
76+
<Target Name="AddNETStandardCompatErrorFileForPackaging"
77+
Condition="'@(NETStandardCompatError)' != ''"
78+
Inputs="%(NETStandardCompatError.Identity)"
79+
Outputs="unused"
80+
BeforeTargets="GetFiles">
81+
<PropertyGroup>
82+
<_NETStandardCompatErrorFilePath>$(BaseIntermediateOutputPath)netstandardcompaterrors\%(NETStandardCompatError.Identity)\$(PackageId).targets</_NETStandardCompatErrorFilePath>
83+
<_NETStandardCompatErrorFileTarget>NETStandardCompatError_$(PackageId.Replace('.', '_'))_$([System.String]::new('%(NETStandardCompatError.Supported)').Replace('.', '_'))</_NETStandardCompatErrorFileTarget>
84+
<_NETStandardCompatErrorFileContent>
85+
<![CDATA[<Project InitialTargets="$(_NETStandardCompatErrorFileTarget)">
86+
<Target Name="$(_NETStandardCompatErrorFileTarget)"
87+
Condition="'%24(SuppressTfmSupportBuildWarnings)' == ''">
88+
<Error Text="$(PackageId) doesn't support %24(TargetFramework). Consider updating your TargetFramework to %(NETStandardCompatError.Supported) or later." />
89+
</Target>
90+
</Project>]]>
91+
</_NETStandardCompatErrorFileContent>
92+
</PropertyGroup>
93+
94+
<WriteLinesToFile File="$(_NETStandardCompatErrorFilePath)"
95+
Lines="$(_NETStandardCompatErrorFileContent)"
96+
Overwrite="true"
97+
WriteOnlyWhenDifferent="true" />
98+
99+
<ItemGroup>
100+
<None Include="$(_NETStandardCompatErrorFilePath)"
101+
PackagePath="buildTransitive\%(NETStandardCompatError.Identity)"
102+
Pack="true" />
103+
<None Include="$(PlaceholderFile)"
104+
PackagePath="buildTransitive\%(NETStandardCompatError.Supported)"
105+
Pack="true" />
106+
<FileWrites Include="$(_NETStandardCompatErrorFilePath)" />
107+
</ItemGroup>
108+
</Target>
73109
</Project>

src/libraries/Microsoft.NETCore.Platforms/src/_._ renamed to eng/_._

File renamed without changes.

src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<ItemGroup>
3939
<Content Condition="'$(AdditionalRuntimeIdentifiers)' == ''" Include="runtime.json" PackagePath="/" />
4040
<Content Condition="'$(AdditionalRuntimeIdentifiers)' != ''" Include="$(IntermediateOutputPath)runtime.json" PackagePath="/" />
41-
<Content Include="_._" PackagePath="lib/netstandard1.0" />
41+
<Content Include="$(PlaceholderFile)" PackagePath="lib/netstandard1.0" />
4242
</ItemGroup>
4343

4444
<ItemGroup>

src/libraries/System.Drawing.Common/pkg/System.Drawing.Common.pkgproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
</ProjectReference>
77
<ProjectReference Include="..\src\System.Drawing.Common.csproj" />
88
<InboxOnTargetFramework Include="$(AllXamarinFrameworks)" />
9-
<PackageFile Include="buildTransitive\System.Drawing.Common.targets"
10-
TargetPath="buildTransitive\netcoreapp2.0" />
11-
<File Include="$(PlaceHolderFile)"
12-
TargetPath="buildTransitive\netcoreapp3.0" />
9+
<NETStandardCompatError Include="netcoreapp2.0" Supported="netcoreapp3.1" />
1310
</ItemGroup>
1411
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
1512
</Project>

src/libraries/System.Drawing.Common/pkg/buildTransitive/System.Drawing.Common.targets

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/libraries/System.Security.Cryptography.Pkcs/pkg/System.Security.Cryptography.Pkcs.pkgproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
<SupportedFramework>net461;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks)</SupportedFramework>
66
</ProjectReference>
77
<ProjectReference Include="..\src\System.Security.Cryptography.Pkcs.csproj" />
8-
<PackageFile Include="buildTransitive\System.Security.Cryptography.Pkcs.targets"
9-
TargetPath="buildTransitive\netcoreapp2.0" />
10-
<File Include="$(PlaceholderFile)"
11-
TargetPath="buildTransitive\netcoreapp3.0" />
8+
<NETStandardCompatError Include="netcoreapp2.0" Supported="netcoreapp3.1" />
129
<!-- Exclude TFMs that aren't supported by the package anymore from validation. -->
1310
<ExcludeHarvestedSupportedFramework Include="netcoreapp1.0;netcoreapp1.1;netcore50;uap10.0;net46" />
1411
</ItemGroup>

src/libraries/System.Security.Cryptography.Pkcs/pkg/buildTransitive/System.Security.Cryptography.Pkcs.targets

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/libraries/System.Speech/pkg/System.Speech.pkgproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
<InboxOnTargetFramework Include="net45">
99
<AsFrameworkReference>true</AsFrameworkReference>
1010
</InboxOnTargetFramework>
11-
<PackageFile Include="buildTransitive\System.Speech.targets"
12-
TargetPath="buildTransitive\netcoreapp2.0" />
13-
<File Include="$(PlaceholderFile)"
14-
TargetPath="buildTransitive\netcoreapp2.1" />
11+
<NETStandardCompatError Include="netcoreapp2.0" Supported="netcoreapp3.1" />
1512
</ItemGroup>
1613
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
1714
</Project>

src/libraries/System.Speech/pkg/buildTransitive/System.Speech.targets

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)