There also used to a Unity-provided package that provided new Roslyn compiler features used for Entities which worked with some older versions, but the last version of the package disables functionality on 2021 (most likely because it had generally equivalent functionality built-in then): https://docs.unity3d.com/Packages/com.unity.roslyn@0.2/changelog/CHANGELOG.html
It might be possible to re-work this to work on 2021 LTS with a newer SDK’s compiler files.
This seems to be unsupported territory in any case. It may be worth specifically making 2022 LTS your baseline if possible.
I replaced the DotNetSdkRoslyn folder of 2021.3, and then added the 6.0.21 version folder copied from 2022.3 under “2021.3.18f1\Editor\Data\NetCoreRuntime\shared\Microsoft.NETCore.App”.
It worked! ! !
I haven’t found any problems yet. Everything works fine after building and running.