Repository: godotengine/godot (language: cpp)

Issue:
.NET: Building GodotSharp is broken in current `master` branch
### Tested versions

- Reproducible in 4.4.dev (4364ed6ccd001cbfe7cb781d074100695c878d90)
- Not reproducible in 4.4.dev6 and earlier

### System information

Fedora 41, .NET 8.0.111

### Issue description

When building the GodotSharp assemblies, I get these errors:

```
$ ./modules/mono/build_scripts/build_assemblies.py --godot-output-dir ./bin
Running MSBuild:  /usr/bin/dotnet msbuild /home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp.sln /restore /t:Build /p:Configuration=Debug /p:NoWarn=1591

Welcome to .NET 8.0!
---------------------
SDK Version: 8.0.111

----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate, view the instructions: https://aka.ms/dotnet-https-linux

----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
MSBuild version 17.8.5+b5265ef37 for .NET
  Determining projects to restore...
  Restored /home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj (in 419 ms).
  Restored /home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharpEditor/GodotSharpEditor.csproj (in 419 ms).
  Restored /home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotPlugins/GodotPlugins.csproj (in 419 ms).
  Restored /home/akien/Godot/godot/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.csproj (in 4.05 sec).
  Godot.SourceGenerators.Internal -> /home/akien/Godot/godot/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/bin/Debug/netstandard2.0/Godot.SourceGenerators.Internal.dll
CSC : warning CS9057: The analyzer assembly '/home/akien/Godot/godot/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/bin/Debug/netstandard2.0/Godot.SourceGenerators.Internal.dll' references version '4.9.0.0' of the compiler, which is newer than the currently running version '4.8.0.0'. [/home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs(7,13): error CS0234: The type or namespace name 'SourceGenerators' does not exist in the namespace 'Godot' (are you missing an assembly reference?) [/home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs(18,6): error CS0246: The type or namespace name 'GenerateUnmanagedCallbacksAttribute' could not be found (are you missing a using directive or an assembly reference?) [/home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs(18,6): error CS0246: The type or namespace name 'GenerateUnmanagedCallbacks' could not be found (are you missing a using directive or an assembly reference?) [/home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs(185,36): error CS8795: Partial method 'NativeFuncs.godotsharp_variant_new_copy(out godot_variant, scoped in godot_variant)' must have an implementation part because it has accessibility modifiers. [/home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
/home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs(319,36): error CS8795: Partial method 'NativeFuncs.godotsharp_string_name_new_copy(out godot_string_name, scoped in godot_string_name)' must have an implementation part because it has accessibility modifiers. [/home/akien/Godot/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]
```
etc.

Full error log:
[godotsharp-errors.txt](https://github.com/user-attachments/files/18163050/godotsharp-errors.txt)

This appears to be a recent regression, possibly from #92131?

<details>
<summary>dotnet --info</summary>

```
.NET SDK:
 Version:           8.0.111
 Commit:            ad116b5ce0
 Workload version:  8.0.100-manifests.7198dcc9

Runtime Environment:
 OS Name:     fedora
 OS Version:  41
 OS Platform: Linux
 RID:         fedora.41-x64
 Base Path:   /usr/lib64/dotnet/sdk/8.0.111/

.NET workloads installed:
 Workload version: 8.0.100-manifests.7198dcc9
There are no installed workloads to display.

Host:
  Version:      8.0.11
  Architecture: x64
  Commit:       9cb3b725e3

.NET SDKs installed:
  8.0.111 [/usr/lib64/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.11 [/usr/lib64/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.11 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/usr/lib64/dotnet]

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
```

</details>

### Steps to reproduce

```
scons module_mono_enabled=yes
./bin/godot.blabla --generate-mono-glue modules/mono/glue
./modules/mono/build_scripts/build_assemblies.py --godot-output-dir ./bin
```

### Minimal reproduction project (MRP)

n/a


Discussion / hints:
> This appears to be a recent regression, possibly from [#92131](https://github.com/godotengine/godot/pull/92131)?

I confirm that reverting that PR locally fixes the issue for me.

Fix patch:
diff --git a/.github/workflows/linux_builds.yml b/.github/workflows/linux_builds.yml
index 193942a1bb3a..6b786a7b5849 100644
--- a/.github/workflows/linux_builds.yml
+++ b/.github/workflows/linux_builds.yml
@@ -140,6 +140,18 @@ jobs:
           python-version: 3.8
           scons-version: 4.0
 
+      - name: Force remove preinstalled .NET SDKs
+        if: matrix.build-mono
+        run: |
+          sudo rm -rf /usr/share/dotnet/sdk/*
+
+      - name: Setup older .NET SDK as baseline
+        if: matrix.build-mono
+        uses: actions/setup-dotnet@v4
+        with:
+          # Targeting the oldest version we want to support to ensure it still builds.
+          dotnet-version: '8.0.100'
+
       - name: Compilation
         uses: ./.github/actions/godot-build
         with:
@@ -163,6 +175,7 @@ jobs:
       - name: Build .NET solutions
         if: matrix.build-mono
         run: |
+          dotnet --info
           ./modules/mono/build_scripts/build_assemblies.py --godot-output-dir=./bin --godot-platform=linuxbsd
 
       - name: Prepare artifact
diff --git a/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.csproj b/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.csproj
index ee607ff279e2..d291199ad04d 100644
--- a/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.csproj
+++ b/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/Godot.SourceGenerators.Internal.csproj
@@ -8,7 +8,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" PrivateAssets="all" />
+    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" PrivateAssets="all" />
     <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
   </ItemGroup>
 


Test patch: