Skip to content

Commit

Permalink
Enables the 'clean method' for .NET Core and .NET Standard 2.1, and f…
Browse files Browse the repository at this point in the history
…ixes an issue with warnings thrown when the library is used as a dependency.
  • Loading branch information
MarkCiliaVincenti committed Dec 14, 2024
1 parent 5c98a5b commit aeb3d7e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net35;net40;net45;netstandard2.0;net5.0;net6.0;net7.0;net9.0</TargetFrameworks>
<TargetFrameworks>net35;net40;net45;netstandard2.0;netcoreapp1.0;netstandard2.1;net5.0;net6.0;net7.0;net9.0</TargetFrameworks>
<Authors>Mark Cilia Vincenti</Authors>
<RepositoryUrl>https://github.com/MarkCiliaVincenti/Backport.System.Threading.Lock.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/MarkCiliaVincenti/Backport.System.Threading.Lock</PackageProjectUrl>
<Copyright>MIT</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>3.0.3</Version>
<Version>3.1.0</Version>
<PackageIcon>logo.png</PackageIcon>
<PackageReleaseNotes>Fixes an issue with the source generator breaking for .NET Framework 3.5 and .NET Framework 4.0.</PackageReleaseNotes>
<PackageReleaseNotes>Enables the 'clean method' for .NET Core and .NET Standard 2.1, and fixes an issue with warnings thrown when the library is used as a dependency.</PackageReleaseNotes>
<Description>A micro-library that backports/polyfills .NET 9.0+'s System.Threading.Lock to prior framework versions (from .NET Framework 3.5 up to .NET 8.0), providing as much backward compatibility as possible. Optionally works as a source generator.</Description>
<Copyright>© 2024 Mark Cilia Vincenti</Copyright>
<PackageTags>System.Threading.Lock,lock,backport,polyfill,backward,compatible,compatibility,synchronization,synchronisation,source generator,analyzer</PackageTags>
<RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<AssemblyVersion>3.0.3.0</AssemblyVersion>
<FileVersion>3.0.3.0</FileVersion>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
<FileVersion>3.1.0.0</FileVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<IsPackable>true</IsPackable>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
Expand Down
2 changes: 1 addition & 1 deletion Backport.System.Threading.Lock/Lock.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET5_0_OR_GREATER && !NET9_0_OR_GREATER
#if (NETSTANDARD2_1_OR_GREATER || NETCOREAPP1_0_OR_GREATER || NET5_0_OR_GREATER) && !NET9_0_OR_GREATER
using System.Runtime.CompilerServices;

namespace System.Threading
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ Adding this library as a dependency allows whatever depends on your project to a

There are two methods for using this library as a dependency:

1. **Clean method:** If you are only targeting .NET 5.0 or greater, then you are strongly recommended to use the clean method.
2. **Factory method:** If you need to target frameworks prior to .NET 5.0 (and that would also include .NET Standard 2.0 and 2.1), then you need to use the factory method because the clean method cannot be hardened against thread aborts which were removed in .NET 5.0.
1. **Clean method:** If you are only targeting .NET Core 1.0+, .NET 5.0+ or .NET Standard 2.1, then you are strongly recommended to use the clean method.
2. **Factory method:** If you need to target the .NET Framework (and that would also include .NET Standard 2.0), then you need to use the factory method because the clean method cannot be hardened against thread aborts which were removed in .NET Core 1.0 and .NET 5.0.

### Clean method (if only targeting .NET 5.0 or greater)
### Clean method (if only targeting .NET Core 1.0+, .NET 5.0+ or .NET Standard 2.1)
In order to get the performance benefits of `System.Threading.Lock`, you must however [multi-target frameworks](https://learn.microsoft.com/en-us/nuget/create-packages/multiple-target-frameworks-project-file) in your `.csproj` file.

Example:
Expand All @@ -71,7 +71,7 @@ Example:
There is also no need to reference this library as a dependency for .NET 9.0+. You can achieve that by having this in your `.csproj` file:

```xml
<PackageReference Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Include="Backport.System.Threading.Lock" Version="3.0.3" />
<PackageReference Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Include="Backport.System.Threading.Lock" Version="3.0.3" />
```

Use this library the same way you would use [System.Threading.Lock](https://learn.microsoft.com/en-us/dotnet/api/system.threading.lock?view=net-9.0). Example:
Expand All @@ -96,8 +96,8 @@ public void Bar()
}
```

### Factory method (if targeting frameworks prior to .NET 5.0)
Due to frameworks prior to .NET 5.0 supporting the notorious `Thread.Abort`, we cannot use the same `System.Threading.Lock` namespace or else the locks would not be hardened against thread aborts, so we need to use a creator method instead.
### Factory method (if targeting the .NET Framework, including .NET Standard 2.0)
Due to the .NET Framewok supporting the notorious `Thread.Abort`, we cannot use the same `System.Threading.Lock` namespace or else the locks would not be hardened against thread aborts, so we need to use a creator method instead.

**IMPORTANT:** You MUST also [multi-target](https://learn.microsoft.com/en-us/nuget/create-packages/multiple-target-frameworks-project-file) .NET 9.0 in your `.csproj` file as well.

Expand Down Expand Up @@ -155,7 +155,7 @@ to:
</PackageReference>
```

Therefore in the clean method (if only targeting .NET 5.0 or greater):
Therefore in the clean method (if only targeting .NET Core 1.0+, .NET 5.0+ or .NET Standard 2.1):

```xml
<PackageReference Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Include="Backport.System.Threading.Lock" Version="3.0.3">
Expand All @@ -164,7 +164,7 @@ Therefore in the clean method (if only targeting .NET 5.0 or greater):
</PackageReference>
```

and in the factory method (if targeting frameworks prior to .NET 5.0):
and in the factory method (if targeting the .NET Framework, including .NET Standard 2.0):

```xml
<ItemGroup>
Expand Down

0 comments on commit aeb3d7e

Please sign in to comment.