https://github.com/annulusgames/csprojlangversionprocessor
A Unity editor extension that automatically overrides the LangVersion property of csproj files and allows the latest C# version to work in the IDE.
https://github.com/annulusgames/csprojlangversionprocessor
Last synced: over 1 year ago
JSON representation
A Unity editor extension that automatically overrides the LangVersion property of csproj files and allows the latest C# version to work in the IDE.
- Host: GitHub
- URL: https://github.com/annulusgames/csprojlangversionprocessor
- Owner: annulusgames
- License: mit
- Created: 2024-01-09T13:09:13.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-26T11:27:03.000Z (about 2 years ago)
- Last Synced: 2025-03-02T03:24:15.686Z (over 1 year ago)
- Language: C#
- Size: 163 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CsprojLangVersionProcessor
A Unity editor extension that automatically overrides the LangVersion property of csproj files and allows the latest C# version to work in the IDE.
[日本語版READMEはこちら](README_JA.md)
## Overview
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.
## Setup
### Requirements
* Unity 2022.2 or later (Unity 2022.3.12f1 or later is recommended)
### Installation
1. Open Package Manager from Window > Package Manager.
2. Click on the "+" button > Add package from git URL.
3. 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:
```json
{
"dependencies": {
"com.annulusgames.csproj-langversion-processor": "https://github.com/AnnulusGames/CsprojLangVersionProcessor.git?path=Assets/CsprojLangVersionProcessor"
}
}
```
## Usage
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.

## Limitations
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](https://github.com/Cysharp/CsprojModifier).
## License
[MIT License](LICENSE)