Unity C# Patch

April 13, 2026 · View on GitHub

release Static Badge

Unleash the full potential by being in sync with the latest C# versions that are configured individually for each .asmdef.

How it works:

  1. Editor Patching: The UnityEditorPatch is responsible for updating the built-in dotnet SDK within the Unity editor. Unity, by default, ships with dotnet version 6.0.21.

  2. Language Version Tracking: UnityPackage keeps track of the C# language version specified in your csc.rsp file that is located alongside each .asmdef. This is required to help Unity to understand which C# version it should use while compiling the code of your .asmdef.

  3. Project File Adjustment: Finally, UnityPackage modifies the .csproj file to reflect the C# version specified in the csc.rsp. This alerts your IDE to the correct language version to use, ensuring it can provide you with all the relevant language features.

Platform Support:

  1. Editor OS support: Mac / Linux / Windows.
  2. Target OS support: Mac / Windows / Linux / iOS / Android / WebGL.
  3. IDE support: Rider / VSCode / Visual Studio.

Supported AssemblyDefinition locations:

  1. Project - everything that is located in Assets/ folder of your project.
  2. Embedded Packages - everything that is located in Packages/ folder of your project.
  3. Local Packages - everything that is located anywhere on your pc with specified path with file: prefix in manifest.

Warning

Patch will modify the Editor installation, so all the projects that are using it will be affected (default for unity C# version will be used for compilation, but from newer (patched) dotnet sdk)

DON'T put .asmdef with its csc.rsp at the root of the project (Assets/). Unity in that case will apply the specified C# version to everything, that may cause compile errors (e.g. field keyword is used as a name in some third party library). Place it in any subfolder (usually Scripts, but doesn't matter, just not at the root)

Opening the editor in safe mode will not apply the patch, so you may see a lot of errors in IDE only. It will be applied when you will exit the safe mode, so when all compile errors from editor console are fixed.

How to Install:

  1. Add the package via git url https://github.com/kandreyc/unity-csharp-patch.git#v1.6.0 or download latest package from releases
  2. Ensure Unity Editor is closed.
  3. Ensure latest dotnet sdk is installed. Download Page
  4. Open terminal at folder EditorPatch~ inside the added package.
  5. Patch the editor (administrative privileges may be required):

Mac:

$ dotnet UnityEditorPatch.dll apply --editor '/Applications/Unity/Hub/Editor/2022.3.21f1' --allow-prerelease

Windows:

$ dotnet UnityEditorPatch.dll apply --editor "C:/Program Files/Unity/Hub/Editor/2022.3.21f1" --allow-prerelease

Linux:

$ dotnet UnityEditorPatch.dll apply --editor ~/Unity/Hub/Editor/2022.3.21f1 --allow-prerelease

    where:

  • --editor - path to the unity editor
  • --allow-prerelease - (optional) allows to use prerelease dotnet sdk

In case if you want to revert the patch:

Mac:

$ dotnet UnityEditorPatch.dll revert --editor '/Applications/Unity/Hub/Editor/2022.3.21f1'

Windows:

$ dotnet UnityEditorPatch.dll revert --editor "C:/Program Files/Unity/Hub/Editor/2022.3.21f1"

Linux:

$ dotnet UnityEditorPatch.dll revert --editor ~/Unity/Hub/Editor/2022.3.21f1

    where:

  • --editor - path to the unity editor
  1. Open the Unity Editor with your project and create a csc.rsp file alongside desired .asmdef with the following content:
-langVersion:14
-nullable:enable

    where:

  • langVersion (optional) - C# version you want to be used for this .asmdef. Values are 10, 11, 12, 13, 14
  • nullable (optional) - allows to use nullables like string? without defining #nullable enable/disable in each file where it used. Values are enable, disable
  1. Refresh the Editor. All required magic should be done here.
  2. Enjoy!

Language Support

C#FeatureSupport
14field keywordYes
14partial events and instance constructorsYes
14nameof unbound generic types support forYes
14Extension membersYes
14Null conditional assignmentYes
14Simple lambda parametersYes
14Implicit span conversionsYes
13params collectionsYes
13New lock type and semanticsNo
13New escape sequence - \eYes
13Method group natural type improvementsYes
13Implicit indexer access in object initializersYes
13Enable ref locals and unsafe contexts in iterators and async methodsYes
13Enable ref struct types to implement interfacesNo
13Allow ref struct types as arguments for type parameters in genericsNo
13Partial properties and indexersYes
13Overload resolution priorityPolySharp
12Primary constructorsYes
12Optional parameters in lambda expressionsYes
12Alias for any typeYes
12Inline arraysNo
12Collection expressionsYes
12InterceptorsNo
11Raw string literalsYes
11static abstract/static virtual members in interfacesNo
11Checked user defined operatorsYes
11Relaxed shift operatorsYes
11Unsigned right-shift operatorYes
11Generic attributesCrash
11UTF-8 string literalsYes
11Newlines in string interpolationsYes
11List patternsYes
11File-local typesYes
11Required membersPolySharp
11Auto-default structsYes
11Pattern match Span<char> or ReadOnlySpan<char> on a constant stringYes
11Extended nameof scopeYes
11Numeric IntPtr and UIntPtrYes
11ref fieldsNo
11ref scoped variablesPolySharp
11Improved method group conversion to delegateYes
10Record structsYes
10Improvements of structure typesYes
10Interpolated string handlerPolySharp
10Global using directivesYes
10File-scoped namespace declarationYes
10Extended property patternsYes
10Lambda expression improvementsYes
10Constant interpolated stringsYes
10Record types can seal ToStringYes
10Assignment and declaration in same deconstructionYes
10Improved definite assignmentYes
10CallerArgumentExpression attributePolySharp
10Enhanced #line pragmaYes

Support:

  • Yes - feature works exactly as expected.
  • No - requires runtime features or BCL changes that Unity does not have. Attempting to use the feature may result in compiler errors.
  • Crash - requires runtime features that Unity does not have. Attempting to use the feature may compile, but will result in crashes.
  • PolySharp - feature works when using PolySharp and/or manually implementing missing APIs.

Motivation

This project was inspired and motivated by two key repositories:

  1. CsprojModifier
  2. UnityRoslynUpdater

While the UnityRoslynUpdater serves its purpose by upgrading the C# version across all projects, my goal was to allow using custom C# version only where it is required. So that my package gives the control of what assemblies should be allowed to use newer C# version, which helps to prevent naming conflicts with embedded/thirdparty libs/sdks, or affect the projects that you don't want to

Inspired by CsprojModifier, I've automated modifying .csproj files based on .asmdef properties, making it possible for your IDE to use the newest C# features.