A Unity editor extension that automatically overrides the LangVersion property of csproj files and allows the latest C# version to work in the IDE.
Csproj LangVersion Processor is an editor extension for overriding the LangVersion
property in csproj files generated by Unity to enable C# 10.0 (11.0) equivalent language features to work in the IDE.
Currently, the C# version officially supported by Unity remains at 9.0. However, starting from Unity 2022.2, the internal compiler version used by Unity has been updated, allowing the compilation of C# 10.0 language features. Additionally, from Unity 2022.3.12f1 onwards, language features equivalent to C# 11.0 are compilable.
Therefore, by explicitly passing -langVersion:preview
to the compiler options, it becomes possible to make C# versions beyond 9.0 work in Unity.
However, the LangVersion
in the generated csproj file is fixed at 9.0, causing IDEs to display compilation errors and making features beyond C# 9.0 unavailable. Csproj LangVersion Processor resolves this issue by automatically rewriting the LangVersion
in the generated csproj file.
Warning
As there haven't been runtime updates, not all language features may be available. Also, please note that this method is not endorsed by Unity, so there's no guarantee of functionality.
- Unity 2022.2 or later (Unity 2022.3.12f1 or later is recommended)
- Open Package Manager from Window > Package Manager.
- Click on the "+" button > Add package from git URL.
- Enter the following URL:
https://github.com/AnnulusGames/CsprojLangVersionProcessor.git?path=Assets/CsprojLangVersionProcessor
Alternatively, open Packages/manifest.json and add the following to the dependencies block:
{
"dependencies": {
"com.annulusgames.csproj-langversion-processor": "https://github.com/AnnulusGames/CsprojLangVersionProcessor.git?path=Assets/CsprojLangVersionProcessor"
}
}
Open ProjectSettings > Player > Other Settings > Script Compilation and add the following to Additional Compiler Arguments (you can also specify options other than preview. If you wish to use C#11.0 equivalent features in versions from Unity 2022.3.12f1 or later, specify preview):
-langVersion:preview
Next, open ProjectSettings > Editor > Csproj LangVersion Processor and specify the LangVersion to be used in the IDE.
With this setup, when adding a cs file, the csproj will be automatically updated. However, manual updating is also possible via Edit > Preferences > External Tools > Regenerate project files.
Csproj LangVersion Processor is a library designed for easy override of the LangVersion property and does not support modifications to other properties or specifying target assemblies. (All csproj files included in the project are affected.)
For more functionalities, it's recommended to use Cysharp/CsprojModifier.