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.