How to use the latest C# versions with Unity 2021.2 and 2022.1

I found a way to replace the compiler on newer Unity versions.
It was only lightly tested, but seems to work.
You need to install the desired .NET sdk version first (Download .NET 6.0 (Linux, macOS, and Windows)).
Then, we do some symlinking (or copying).
I’m using 2022.1.0a9 and 6.0.100-rc.1.21463.6 as example below. Your installed .NET might have different version.
Note: You need to rename or delete the original folders.

symlink (or copy)
c:\Program Files\dotnet
as
c:\Program Files\Unity\Hub\Editor\2022.1.0a9\Editor\Data\NetCoreRuntime\

symlink (or copy)
c:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Roslyn\bincore
as
c:\Program Files\Unity\Hub\Editor\2022.1.0a9\Editor\Data\DotNetSdkRoslyn\

I initially posted this this gh issue but decided to post it here as well, since people might search for it here.

Note that I don’t know the consequences of doing this and I just did it because I could. Remember to use source control and/or backup your project before following instructions from strangers from the internet.

2 Likes

One of downsides of such solution is that it affect all projects opened with specific Unity version on specific machine. Also it requires specific preparation of Unity after instalation. This makes it much harder to add new developer to project o use build machines (or impossible if you don’t have modification rights on it)

I don’t saying this solution is bad but it not goes in par with CSharpCompilerSettingsForUnity

1 Like

For sure.

I wonder if there’s anything in their new Bee thing that we could use to redirect those folders.
Since they now seems to use more of the .NET Core runtime, it’s not as streamlined as it was before (when we just needed to point to a new compiler and everything would work).

1 Like