No CMAKE_CSharp_COMPILER could be found

I am trying to create a Visual Studio 2022 solution that contains C# projects, but I’m seeing the failure No CMAKE_CSharp_COMPILER could be found.

Running the configure step with --trace-redirect I can see that the C# compiler is found but fails to compile due to

C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702 /fullpaths /nostdlib+ /platform:anycpu32bitpreferred /define:Platformx64;PlatformToolsetv143 /highentropyva+ /nullable:enable /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Core.dll" /debug:pdbonly /out:obj\x64\Debug\CompilerIdCSharp.exe /subsystemversion:6.00 /target:exe /warnaserror+ /utf8output /deterministic+ /langversion:7.3 /analyzerconfig:D:\INVBUILD\wombat-software\.editorconfig /analyzerconfig:D:\INVBUILD\wombat-software\src\.editorconfig CMakeCSharpCompilerId.cs "obj\x64\Debug\.NETFramework,Version=v4.7.2.AssemblyAttributes.cs" /warnaserror+:MSB3270
CSC : error CS8630: Invalid 'nullable' value: 'Enable' for C# 7.3. Please use language version '8.0' or greater.

I am using cmake version 3.29.2.

Is there a way to influence either the C# language version selection, or whether “nullable” is enabled/disabled during CSharp compiler identification?

After some further testing I found the culprit for my issue - there is a Directory.Build.props file in the directory above the build output directory that enables “nullable” for all projects. When CMake is performing CSharp compiler detection it appears to be picking up some of the settings from Directory.Build.props. I was able to avoid the issue by moving the build output directory above where Directory.Build.props is located.

Should CMake be protecting against inheriting settings from Directory.Build.props when detecting a CSharp compiler? Perhaps it can create an empty Directory.Build.props file next to the .csproj file used to compile the test program.