Awesome
Unity Roslyn Updater
A tool to update the Roslyn compiler and C# language versions for a Unity installation.
Usage
NOTE: This will modify your Unity installation folder, administrative privileges are required!
UnityRoslynUpdater.exe <path to Unity Editor folder>
For example: UnityRoslynUpdater.exe "C:\Program Files\Unity\Hub\Editor\2022.3.8f1\Editor"
Using C# 12+
C# 11 is the most recent language version that works correctly with Visual Studio in a UnityRoslynUpdater-patched Unity install.
This is because the com.unity.ide.visualstudio
package does not recognize newer versions, and will limit the <LangVersion>
property in generated .csproj
files to 11
.
To work around this issue, create a Directory.Build.targets
file next to your project's Assets
directory containing the following (replace 12
with your desired language version):
<Project>
<PropertyGroup>
<LangVersion>12</LangVersion>
</PropertyGroup>
</Project>
After you have done this, navigate to Edit -> Project Settings -> Player in Unity, and scroll down to the 'Additional Compiler Arguments' section. Add a new entry containing -langversion:12
(again replacing 12
with your desired language version).
Note that you may need to delete the Visual Studio cache directory (.vs
) in order for these changes to take effect.
Language Support
- Working
- Feature works exactly as expected.
- PolySharp
- Feature works when using PolySharp and/or manually implementing missing APIs.
- Not Supported
- 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.
C# 13
Feature | Status |
---|---|
params collections | Working |
New lock type and semantics | Not Supported |
New escape sequence - \e | Working |
Method group natural type improvements | Working |
Implicit indexer access in object initializers | Working |
Enable ref locals and unsafe contexts in iterators and async methods | Working |
Enable ref struct types to implement interfaces | Not Supported |
Allow ref struct types as arguments for type parameters in generics | Not Supported |
Partial properties and indexers | Working |
Overload resolution priority | PolySharp |
The field keyword | Working |
C# 12
Feature | Status |
---|---|
Primary constructors | Working |
Optional parameters in lambda expressions | Working |
Alias any type | Working |
Inline arrays | Not Supported |
Collection expressions | Working |
Interceptors | Not Supported |
C# 11
Feature | Status |
---|---|
Raw string literals | Working |
static abstract /static virtual members in interfaces | Not Supported |
Checked user defined operators | Working |
Relaxed shift operators | Working |
Unsigned right-shift operator | Working |
Generic attributes | Crash |
UTF-8 string literals | Working |
Newlines in string interpolations | Working |
List patterns | Working |
File-local types | Working |
Required members | PolySharp |
Auto-default structs | Working |
Pattern match Span<char> or ReadOnlySpan<char> on a constant string | Working |
Extended nameof scope | Working |
Numeric IntPtr and UIntPtr | Working |
ref fields | Not Supported |
ref scoped variables | PolySharp |
Improved method group conversion to delegate | Working |
C# 10
Feature | Status |
---|---|
Record structs | Working |
Improvements of structure types | Working |
Interpolated string handler | PolySharp |
Global using directives | Working |
File-scoped namespace declaration | Working<sup>1</sup> |
Extended property patterns | Working |
Lambda expression improvements | Working |
Constant interpolated strings | Working |
Record types can seal ToString | Working |
Assignment and declaration in same deconstruction | Working |
Improved definite assignment | Working |
Allow AsyncMethodBuilder attribute on methods | Not Supported<sup>2</sup> |
CallerArgumentExpression attribute | PolySharp |
Enhanced #line pragma | Working |
- Unity 2021 and earlier require UnityNamespacePatch to be installed.
AsyncMethodBuilderAttribute
requires changes to its[AttributeUsage]
attribute for this to work.