Skip to content

Commit

Permalink
Centralize NETSTANDARD2_1_OR_GREATER define in .targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Nov 22, 2022
1 parent 9d9de23 commit 765901a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 29 deletions.
5 changes: 0 additions & 5 deletions src/CommunityToolkit.Common/CommunityToolkit.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
<PackageTags>Incremental;Loading;Collection;IncrementalLoadingCollection;String;Array;Extensions;Helpers</PackageTags>
</PropertyGroup>

<!-- .NET Standard 2.1 and .NET 6 already have [NotNullIfNotNull] and [NotNullWhen] -->
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
</PropertyGroup>

<!-- Necessary polyfills -->
<PropertyGroup>
<PolySharpIncludeGeneratedTypes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,20 @@
</PropertyGroup>

<Choose>
<When Condition="'$(TargetFramework)' == 'netstandard2.0'">

<!-- .NET Standard 2.0 doesn't have the Span<T> type -->
<!-- .NET Standard 2.0 doesn't have the Span<T> type -->
<When Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>
</When>

<!-- .NET Standard 2.1 doesn't have the Unsafe type -->
<When Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
</PropertyGroup>

<!-- .NET Standard 2.1 doesn't have the Unsafe type -->
<ItemGroup>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>
</When>

<!-- For the .NET 6 target, simply define NETSTANDARD2_1_OR_GREATER too -->
<When Condition="'$(TargetFramework)' == 'net6.0'">
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
</PropertyGroup>
</When>
</Choose>

<!-- Necessary polyfills -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,12 @@
</ItemGroup>
</When>

<!-- .NET Standard 2.1 doesn't have the Unsafe type -->
<When Condition="'$(TargetFramework)' == 'netstandard2.1'">

<!-- .NET Standard 2.1 doesn't have the Unsafe type -->
<ItemGroup>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
</ItemGroup>
</When>

<When Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0'">

<!-- NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1 and .NET 6 and above -->
<PropertyGroup>
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
</PropertyGroup>
</When>
</Choose>

<!-- Necessary polyfills -->
Expand Down
5 changes: 5 additions & 0 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<Project>
<Import Project="..\Directory.Build.targets" />

<!-- Define NETSTANDARD2_1_OR_GREATER for .NET Standard 2.1 targets and above -->
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0'">
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
</PropertyGroup>

<!-- Configure trimming for projects on .NET 6 and above -->
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0'">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
Expand Down

0 comments on commit 765901a

Please sign in to comment.