Skip to content

Commit

Permalink
Detect Microsoft.Bcl.Memory and disable related polyfills (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz authored Feb 3, 2025
1 parent 6c18a87 commit f362e68
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion PolyShim/NetCore30/Index.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The following comment is required to instruct analyzers to skip this file
// <auto-generated/>

#if (NETCOREAPP && !NETCOREAPP3_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER)
#if !FEATURE_INDEXRANGE
#nullable enable
// ReSharper disable RedundantUsingDirective
// ReSharper disable CheckNamespace
Expand Down
2 changes: 1 addition & 1 deletion PolyShim/NetCore30/Range.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The following comment is required to instruct analyzers to skip this file
// <auto-generated/>

#if (NETCOREAPP && !NETCOREAPP3_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER)
#if !FEATURE_INDEXRANGE
#nullable enable
// ReSharper disable RedundantUsingDirective
// ReSharper disable CheckNamespace
Expand Down
2 changes: 1 addition & 1 deletion PolyShim/NetCore30/RuntimeHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The following comment is required to instruct analyzers to skip this file
// <auto-generated/>

#if (NETCOREAPP && !NETCOREAPP3_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER)
#if !FEATURE_INDEXRANGE
#nullable enable
// ReSharper disable RedundantUsingDirective
// ReSharper disable CheckNamespace
Expand Down
1 change: 1 addition & 0 deletions PolyShim/PolyShim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" PrivateAssets="all" Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard' AND $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '2.0'))" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" PrivateAssets="all" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '4.6.1'))" />
<PackageReference Include="Microsoft.Bcl.Async" Version="1.0.168" PrivateAssets="all" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' AND $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '4.0'))" />
<PackageReference Include="Microsoft.Bcl.Memory" Version="9.0.1" PrivateAssets="all" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' AND $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '4.6.2'))" />
<PackageReference Include="Microsoft.Net.Http" Version="2.2.29" PrivateAssets="all" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' AND $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '4.0'))" />
</ItemGroup>

Expand Down
7 changes: 7 additions & 0 deletions PolyShim/PolyShim.targets
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
<FeatureHttpClient Condition="$(IsNetCoreApp) AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '1.0'))">true</FeatureHttpClient>
<DefineConstants Condition="$(FeatureHttpClient)">$(DefineConstants);FEATURE_HTTPCLIENT</DefineConstants>

<FeatureIndexRange>false</FeatureIndexRange>
<FeatureIndexRange Condition="@(Reference->AnyHaveMetadataValue('Identity', 'Microsoft.Bcl.Memory'))">true</FeatureIndexRange>
<FeatureIndexRange Condition="@(PackageDependencies->AnyHaveMetadataValue('Identity', 'Microsoft.Bcl.Memory'))">true</FeatureIndexRange>
<FeatureIndexRange Condition="$(IsNetStandard) AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '2.1'))">true</FeatureIndexRange>
<FeatureIndexRange Condition="$(IsNetCoreApp) AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '3.0'))">true</FeatureIndexRange>
<DefineConstants Condition="$(FeatureIndexRange)">$(DefineConstants);FEATURE_INDEXRANGE</DefineConstants>

<FeatureManagement>false</FeatureManagement>
<FeatureManagement Condition="@(Reference->AnyHaveMetadataValue('Identity', 'System.Management'))">true</FeatureManagement>
<FeatureManagement Condition="@(PackageDependencies->AnyHaveMetadataValue('Identity', 'System.Management'))">true</FeatureManagement>
Expand Down
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Currently, **PolyShim** has integration with the following packages:
- [`Microsoft.Bcl.Async`](https://nuget.org/packages/Microsoft.Bcl.Async)`Task`, `Task<T>`, etc (wider support than the `System.*` variant).
- [`Microsoft.Bcl.AsyncInterfaces`](https://nuget.org/packages/Microsoft.Bcl.AsyncInterfaces)`IAsyncEnumerable<T>`, `IAsyncDisposable`, etc.
- [`Microsoft.Bcl.HashCode`](https://nuget.org/packages/Microsoft.Bcl.HashCode)`HashCode`, etc.
- [`Microsoft.Bcl.Memory`](https://nuget.org/packages/Microsoft.Bcl.Memory)`Index`, `Range`, etc.
- [`Microsoft.Net.Http`](https://nuget.org/packages/Microsoft.Net.Http)`HttpClient`, `HttpContent`, etc (wider support than the `System.*` variant).

For example, adding a reference to the `System.Memory` package will enable **PolyShim**'s polyfills that offer `Span<T>` and `Memory<T>`-based method overloads on various built-in types, such as `Stream`:
Expand Down

0 comments on commit f362e68

Please sign in to comment.