Unleash the full potential by being in sync with the latest C# versions that are configured individually for each .asmdef
.
-
Editor Patching: The
UnityEditorPatch
is responsible for updating the built-in dotnet SDK within the Unity editor. Unity, by default, ships with dotnet version6.0.21
. -
Language Version Tracking:
UnityPackage
keeps track of the C# language version specified in yourcsc.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
. -
Project File Adjustment: Finally,
UnityPackage
modifies the.csproj
file to reflect the C# version specified in thecsc.rsp
. This alerts your IDE to the correct language version to use, ensuring it can provide you with all the relevant language features.
- Project - everything that is located in
Assets/
folder of your project. - Embedded Packages - everything that is located in
Packages/
folder of your project. - Local Packages - everything that is located anywhere on your pc with specified path with
file:
prefix in manifest.
Warning
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)
Note
OS support: Mac / Linux / Windows. You can backup your editor just in case, but should be fine.
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)
Tested on target platforms: Mac / Windows / Linux / iOS / Android / WebGL
Tested in IDEs:
Rider 2025.1
with integration package [email protected]
VSCode 1.99.3
with integration package [email protected]
Visual Studio Community 2022 17.13.6
with integration package [email protected]
- Add the package via git url
https://github.com/kandreyc/unity-csharp-patch.git#v1.4.0
- Ensure Unity Editor is closed.
- Ensure latest dotnet sdk is installed. Download Page
- Open terminal at folder
EditorPatch~
inside the added package. - Patch the editor (administrative privileges are required):
$ dotnet UnityEditorPatch.dll apply --editor '/Applications/Unity/Hub/Editor/2022.3.21f1' --allow-prerelease
where --editor
- path to the unity editor
where --allow-prerelease
- (optional) allows to use prerelease dotnet sdk
In case if you want to revert the patch:
$ dotnet UnityEditorPatch.dll revert --editor '/Applications/Unity/Hub/Editor/2022.3.21f1'
where --editor
- path to the unity editor
- Open the Unity Editor with your project and create a
csc.rsp
file alongside desired.asmdef
with the following content:
-langVersion:13
-nullable:enable
where:
langVersion
(optional) - C# version you want to be used for this.asmdef
. Values are10
,11
,12
,13
,preview
nullable
(optional) - allows to use nullables likestring?
without defining#nullable enable/disable
in each file where it used. Values areenable
,disable
- Refresh the Editor. All required magic should be done here.
- Enjoy!
Note
preview
features support of .net 10 in Rider
/ Visual Studio
is still in development.
Code will compile and work, but you may suffer from errors in IDE.
Currently only VSCode
supports all new features
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.
This project was inspired and motivated by two key repositories:
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.