Skip to content

Commit

Permalink
Generate targets files that throws for unsupported netstandard applic…
Browse files Browse the repository at this point in the history
…able 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.
  • Loading branch information
ViktorHofer committed May 26, 2021
1 parent f584c74 commit 293d472
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 32 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
<GeneratePackage Condition="(('$(PreReleaseVersionLabel)' == 'servicing' or
'$(GitHubRepositoryName)' == 'runtimelab') and
'$(MSBuildProjectExtension)' != '.sfxproj')">false</GeneratePackage>
<PlaceholderFile>$(RepositoryEngineeringDir)_._</PlaceholderFile>
</PropertyGroup>

<!-- Language configuration -->
Expand Down
36 changes: 36 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<PackageDescription Condition="'$(PackageDescription)' == '' and '$(UseRuntimePackageDisclaimer)' == 'true'">$(RuntimePackageDisclaimer)</PackageDescription>
<!-- Keep in sync as required by the Packaging SDK in Arcade. -->
<Description>$(PackageDescription)</Description>
<BeforePack>$(BeforePack);AddNETStandardCompatErrorFileForPackaging</BeforePack>
</PropertyGroup>

<!-- Remove when https://github.com/NuGet/Home/issues/10405 is implemented and consumed. -->
Expand All @@ -70,4 +71,39 @@
<PackDependsOn />
</PropertyGroup>
</Target>

<!-- Add targets file that marks a .NETStandard applicable tfm as unsupported. -->
<Target Name="AddNETStandardCompatErrorFileForPackaging"
Condition="'@(NETStandardCompatError)' != ''"
Inputs="%(NETStandardCompatError.Identity)"
Outputs="unused"
BeforeTargets="GetFiles">
<PropertyGroup>
<_NETStandardCompatErrorFilePath>$(BaseIntermediateOutputPath)netstandardcompaterrors\%(NETStandardCompatError.Identity)\$(PackageId).targets</_NETStandardCompatErrorFilePath>
<_NETStandardCompatErrorFileTarget>NETStandardCompatError_$(PackageId.Replace('.', '_'))_$([System.String]::new('%(NETStandardCompatError.Supported)').Replace('.', '_'))</_NETStandardCompatErrorFileTarget>
<_NETStandardCompatErrorFileContent>
<![CDATA[<Project InitialTargets="$(_NETStandardCompatErrorFileTarget)">
<Target Name="$(_NETStandardCompatErrorFileTarget)"
Condition="'%24(SuppressTfmSupportBuildWarnings)' == ''">
<Error Text="$(PackageId) doesn't support %24(TargetFramework). Consider updating your TargetFramework to %(NETStandardCompatError.Supported) or later." />
</Target>
</Project>]]>
</_NETStandardCompatErrorFileContent>
</PropertyGroup>

<WriteLinesToFile File="$(_NETStandardCompatErrorFilePath)"
Lines="$(_NETStandardCompatErrorFileContent)"
Overwrite="true"
WriteOnlyWhenDifferent="true" />

<ItemGroup>
<None Include="$(_NETStandardCompatErrorFilePath)"
PackagePath="buildTransitive\%(NETStandardCompatError.Identity)"
Pack="true" />
<None Include="$(PlaceholderFile)"
PackagePath="buildTransitive\%(NETStandardCompatError.Supported)"
Pack="true" />
<FileWrites Include="$(_NETStandardCompatErrorFilePath)" />
</ItemGroup>
</Target>
</Project>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<ItemGroup>
<Content Condition="'$(AdditionalRuntimeIdentifiers)' == ''" Include="runtime.json" PackagePath="/" />
<Content Condition="'$(AdditionalRuntimeIdentifiers)' != ''" Include="$(IntermediateOutputPath)runtime.json" PackagePath="/" />
<Content Include="_._" PackagePath="lib/netstandard1.0" />
<Content Include="$(PlaceholderFile)" PackagePath="lib/netstandard1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
</ProjectReference>
<ProjectReference Include="..\src\System.Drawing.Common.csproj" />
<InboxOnTargetFramework Include="$(AllXamarinFrameworks)" />
<PackageFile Include="buildTransitive\System.Drawing.Common.targets"
TargetPath="buildTransitive\netcoreapp2.0" />
<File Include="$(PlaceHolderFile)"
TargetPath="buildTransitive\netcoreapp3.0" />
<NETStandardCompatError Include="netcoreapp2.0" Supported="netcoreapp3.1" />
</ItemGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
<SupportedFramework>net461;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.Security.Cryptography.Pkcs.csproj" />
<PackageFile Include="buildTransitive\System.Security.Cryptography.Pkcs.targets"
TargetPath="buildTransitive\netcoreapp2.0" />
<File Include="$(PlaceholderFile)"
TargetPath="buildTransitive\netcoreapp3.0" />
<NETStandardCompatError Include="netcoreapp2.0" Supported="netcoreapp3.1" />
<!-- Exclude TFMs that aren't supported by the package anymore from validation. -->
<ExcludeHarvestedSupportedFramework Include="netcoreapp1.0;netcoreapp1.1;netcore50;uap10.0;net46" />
</ItemGroup>
Expand Down

This file was deleted.

5 changes: 1 addition & 4 deletions src/libraries/System.Speech/pkg/System.Speech.pkgproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
<InboxOnTargetFramework Include="net45">
<AsFrameworkReference>true</AsFrameworkReference>
</InboxOnTargetFramework>
<PackageFile Include="buildTransitive\System.Speech.targets"
TargetPath="buildTransitive\netcoreapp2.0" />
<File Include="$(PlaceholderFile)"
TargetPath="buildTransitive\netcoreapp2.1" />
<NETStandardCompatError Include="netcoreapp2.0" Supported="netcoreapp3.1" />
</ItemGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
</Project>

This file was deleted.

0 comments on commit 293d472

Please sign in to comment.