Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViktor Hofer <viktor.hofer@microsoft.com>2021-08-10 08:19:06 +0300
committerGitHub <noreply@github.com>2021-08-10 08:19:06 +0300
commit4d82932722b56924598708f991961a75e5a90b36 (patch)
tree45324b86553cbacbe01f5552f918c5bb514f1fbf /eng/packaging.targets
parent08166d32268e5260dc3304de21f7750a03978a0a (diff)
Automatically generate .NETStandard compat errors (#57057)
* Automatically generate .NETStandard compat errors Before this change, a project had to explicitly add a NETStandardCompatError item to declare that a given tfm range shouldn't be supported when packaging. Automate this logic so that projects don't need to specify the item themselves anymore. Instead condition the NETStandardCompatError target calcuation logic on the existence of both a .NETStandard and a .NETCoreApp tfm. * Update Directory.Build.targets * Update packaging.targets * Update eng/packaging.targets Co-authored-by: Santiago Fernandez Madero <safern@microsoft.com> Co-authored-by: Santiago Fernandez Madero <safern@microsoft.com>
Diffstat (limited to 'eng/packaging.targets')
-rw-r--r--eng/packaging.targets46
1 files changed, 45 insertions, 1 deletions
diff --git a/eng/packaging.targets b/eng/packaging.targets
index 30d7ef75d98..4da97847376 100644
--- a/eng/packaging.targets
+++ b/eng/packaging.targets
@@ -12,7 +12,7 @@
<!-- Don't include target platform specific dependencies, since we use the target platform to represent RIDs instead -->
<SuppressDependenciesWhenPacking Condition="'$(ExcludeFromPackage)' == 'true' or ('$(TargetsAnyOS)' != 'true' and $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0')))">true</SuppressDependenciesWhenPacking>
<PackageDesignerMarkerFile>$(MSBuildThisFileDirectory)useSharedDesignerContext.txt</PackageDesignerMarkerFile>
- <GenerateNuspecDependsOn>IncludeAnalyzersInPackage;$(GenerateNuspecDependsOn)</GenerateNuspecDependsOn>
+ <BeforePack>AddNETStandardCompatErrorFileForPackaging;IncludeAnalyzersInPackage;$(BeforePack)</BeforePack>
<!-- Generate packages in the allconfigurations build. -->
<GeneratePackageOnBuild Condition="'$(BuildAllConfigurations)' == 'true'">true</GeneratePackageOnBuild>
<!-- Search for the documentation file in the intellisense package and otherwise pick up the generated one. -->
@@ -127,4 +127,48 @@
</ItemGroup>
</Target>
+ <!-- Include a netstandard compat error if the project targets both .NETStandard and
+ .NETCoreApp. This prohibits users to consume packages on an older .NETCoreApp version
+ than the minimum supported one. -->
+ <ItemGroup Condition="'$(DisableNETStandardCompatErrorForNETCoreApp)' != 'true'">
+ <NETStandardCompatError Include="netcoreapp2.0"
+ Supported="$(NetCoreAppMinimum)"
+ Condition="$(TargetFrameworks.Contains('netstandard2.')) and
+ ($(TargetFrameworks.Contains('$(NetCoreAppMinimum)')) or $(TargetFrameworks.Contains('$(NetCoreAppCurrent)')))" />
+ </ItemGroup>
+
+ <!-- Add targets file that marks a .NETStandard applicable tfm as unsupported. -->
+ <Target Name="AddNETStandardCompatErrorFileForPackaging"
+ Condition="'@(NETStandardCompatError)' != ''"
+ Inputs="%(NETStandardCompatError.Identity)"
+ Outputs="unused">
+ <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>