Home

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

C# 13

FeatureStatus
params collectionsWorking
New lock type and semanticsNot Supported
New escape sequence - \eWorking
Method group natural type improvementsWorking
Implicit indexer access in object initializersWorking
Enable ref locals and unsafe contexts in iterators and async methodsWorking
Enable ref struct types to implement interfacesNot Supported
Allow ref struct types as arguments for type parameters in genericsNot Supported
Partial properties and indexersWorking
Overload resolution priorityPolySharp
The field keywordWorking

C# 12

FeatureStatus
Primary constructorsWorking
Optional parameters in lambda expressionsWorking
Alias any typeWorking
Inline arraysNot Supported
Collection expressionsWorking
InterceptorsNot Supported

C# 11

FeatureStatus
Raw string literalsWorking
static abstract/static virtual members in interfacesNot Supported
Checked user defined operatorsWorking
Relaxed shift operatorsWorking
Unsigned right-shift operatorWorking
Generic attributesCrash
UTF-8 string literalsWorking
Newlines in string interpolationsWorking
List patternsWorking
File-local typesWorking
Required membersPolySharp
Auto-default structsWorking
Pattern match Span<char> or ReadOnlySpan<char> on a constant stringWorking
Extended nameof scopeWorking
Numeric IntPtr and UIntPtrWorking
ref fieldsNot Supported
ref scoped variablesPolySharp
Improved method group conversion to delegateWorking

C# 10

FeatureStatus
Record structsWorking
Improvements of structure typesWorking
Interpolated string handlerPolySharp
Global using directivesWorking
File-scoped namespace declarationWorking<sup>1</sup>
Extended property patternsWorking
Lambda expression improvementsWorking
Constant interpolated stringsWorking
Record types can seal ToStringWorking
Assignment and declaration in same deconstructionWorking
Improved definite assignmentWorking
Allow AsyncMethodBuilder attribute on methodsNot Supported<sup>2</sup>
CallerArgumentExpression attributePolySharp
Enhanced #line pragmaWorking
  1. Unity 2021 and earlier require UnityNamespacePatch to be installed.
  2. AsyncMethodBuilderAttribute requires changes to its [AttributeUsage] attribute for this to work.