PolySharp 1.13.2

This package has a SemVer 2.0.0 package version: 1.13.2+0596138b111ff552137684c6f7c3373805d2e3d2.
dotnet add package PolySharp --version 1.13.2
NuGet\Install-Package PolySharp -Version 1.13.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PolySharp" Version="1.13.2">
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PolySharp --version 1.13.2
#r "nuget: PolySharp, 1.13.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PolySharp as a Cake Addin
#addin nuget:?package=PolySharp&version=1.13.2

// Install PolySharp as a Cake Tool
#tool nuget:?package=PolySharp&version=1.13.2


What is it? 🚀

PolySharp provides generated, source-only polyfills for C# language features, to easily use all runtime-agnostic features downlevel. The package is distributed as a source generator, so that it will automatically detect which polyfills are needed depending on the target framework and project in use: just add a reference to PolySharp, set your C# language version to latest, and have fun!

TLDR? What is this for? ✨

Put simply: are you working on .NET Framework, or UWP, or some other older .NET runtime and still would like to use all the cool new features that C# 11 has? Well this library lets you do just that! It will generate for you all the "magic types" that the C# compiler needs to "see" in order for it to allow using new language features even if you're not using the latest framework out there.

Here's an example of some of the new features that PolySharp can enable downlevel:


Note: not all the new C# features can be "tricked" this way (eg. those requiring runtime support, such as static abstract members, still won't work). But almost everything else will (eg. nullability annotations, pattern matching, etc.), and this applies to a big number of new C# features. Try PolySharp out, don't get stuck on C# 6.0 or other older versions! 🎉

Note: use on .NET Framework 3.5 is particularly limited due to shortcomings of the BCL there. In particular, the System.Range type will not be generated unless System.ValueTuple is referenced (meaning that eg. list patterns won't work by default), and some features such as records will not be usable at all due to the C# compiler missing some necessary APIs that cannot be polyfilled. All other features should work as expected.

Documentation 📖

PolySharp includes the following polyfills:

To leverage them, make sure to bump your C# language version. You can do this by setting the <LangVersion> MSBuild property in your project. For instance, by adding <LangVersion>11.0</LangVersion> (or your desired C# version) to the first <PropertyGroup> of your .csproj file. For more info on this, see here, but remember that you don't need to manually copy polyfills anymore: simply adding a reference to PolySharp will do this for you automatically.

It also includes the following optional runtime-supported polyfills:

  • Reflection annotation attributes (see docs):
    • [DynamicallyAccessedMembers]
    • [DynamicDependency]
    • [RequiresUnreferencedCode]
    • [RequiresDynamicCode]
    • [UnconditionalSuppressMessage]
    • [RequiresAssemblyFiles]
  • [StackTraceHidden] (see here)
  • [UnmanagedCallersOnly] (see docs))
  • Platform support annotation attributes (see docs):
    • [ObsoletedOSPlatform]
    • [SupportedOSPlatform]
    • [SupportedOSPlatformGuard]
    • [TargetPlatform]
    • [UnsupportedOSPlatform]
    • [UnsupportedOSPlatformGuard]
  • [SuppressGCTransition] (see here)
  • [DisableRuntimeMarshalling] (see here)

Options ⚙️

PolySharp's generation can be configured through some MSBuild properties to set in consuming projects.

The following properties are available:

  • "PolySharpUsePublicAccessibilityForGeneratedTypes": makes all generated types public.
  • "PolySharpIncludeRuntimeSupportedAttributes": enables polyfills for (dummy) runtime-supported attributes too.
  • "PolySharpUseInteropServices2NamespaceForUnmanagedCallersOnlyAttribute": moves [UnmanagedCallersOnly].
  • "PolySharpExcludeGeneratedTypes": excludes specific types from generation (';' or ',' separated type names).
  • "PolySharpIncludeGeneratedTypes": only includes specific types for generation (';' or ',' separated type names).
  • "PolySharpExcludeTypeForwardedToDeclarations": never generates any [TypeForwardedTo] declarations.
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages (10)

Showing the top 5 NuGet packages that depend on PolySharp:

Package Downloads

Support classes for code generated by SharpGen.


C# COM Interop classes for use with SharpGenTools generated libraries


A C# client for the API of https://gocardless.com/bank-account-data (formerly https://nordigen.com/)


Package Description

Subnautica.Nautilus The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Core library for modding Subnautica.

GitHub repositories (46)

Showing the top 5 popular GitHub repositories that depend on PolySharp:

Repository Stars
Building the best file manager for Windows
Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
Simple .NET logging with fully-structured events
GraphQL for .NET
WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
Version Downloads Last updated
1.13.2 110,438 5/16/2023
1.13.1 49,203 4/6/2023
1.12.1 159,025 1/21/2023
1.10.0 113,591 1/15/2023
1.9.0 1,593 1/14/2023
1.8.3 9,086 1/9/2023
1.8.2 104 1/8/2023
1.8.1 14,547 11/22/2022
1.8.0 731 11/16/2022
1.7.1 16,095 10/29/2022
1.7.0 93 10/28/2022
1.6.0 241 10/26/2022
1.5.0 88 10/26/2022
1.4.0 80 10/25/2022
1.3.0 252 10/23/2022
1.2.0 77 10/22/2022
1.1.0 70 10/22/2022
1.0.1 77 10/22/2022
1.0.0 998 10/22/2022