godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.48k stars 21.26k forks source link

.NET Export Ignores Solution Path and Incorrectly Appends Assembly Name for Projects in Subdirectories #98804

Open mrdelicate opened 3 weeks ago

mrdelicate commented 3 weeks ago

Tested versions

Reproducible in: 4.3.stable.mono.official [77dcf97d8]

System information

Godot v4.3.stable.mono - Windows 10.0.22631 - Vulkan (Mobile) - dedicated Radeon RX 580 Series (Advanced Micro Devices, Inc.; 26.20.13002.133) - AMD Ryzen 5 2600 Six-Core Processor (12 Threads)

Issue description

During project export, Godot's .NET integration incorrectly constructs the solution file path for C# projects that exist as part of a larger solution. The export process appears to ignore the configured solution path and instead tries to find a solution file named after the assembly name, whereas normal project execution (F5) works correctly with the specified solution path.

The export process fails with the error:

This project contains C# files but no solution file was found at the following path: 
C:/Repos/my-game/src/MyGame.Server/../../MyGame.sln/MyGame.Server.sln

The export process incorrectly:

  1. Ignores the specified solution filename in the Solution Directory setting
  2. Attempts to find a solution file named after the assembly name
  3. Appends this assumed filename to the solution directory path

Steps to reproduce

  1. Create a new Godot 4.3 C# project in a subdirectory of a larger solution
  2. Configure project settings:
    Assembly Name: "MyGame.Server"
    Solution Directory: "../../MyGame.sln"
  3. Verify that the project runs correctly with F5
  4. Attempt to export the project using any preset
  5. Observe the error about not finding the solution file

Workaround Steps

You can work around this issue by either:

  1. Create a server-specific solution in the Godot project directory:

    cd src/MyGame.Server
    dotnet new sln -n MyGame.Server
    dotnet sln add MyGame.Server.csproj
    dotnet sln add ../../src/MyGame.Shared/MyGame.Shared.csproj
    dotnet sln add ../../src/MyGame.Shared.Godot/MyGame.Shared.Godot.csproj
  2. Or create a symbolic link in the Godot project directory:

    cd src/MyGame.Server
    mklink MyGame.Server.sln ..\..\MyGame.sln

Both workarounds are suboptimal as they:

Minimal reproduction project (MRP)

Not at the moment.

raulsntos commented 3 weeks ago

The Solution Directory option, as its name implies, contains the path to the directory that contains the solution file, not the path to the file itself. So it has no way of specifying the name of the solution file, which currently is always assumed to match the project name. There's a PR to add a new option to allow configuring the name of the solution file:

Normal project execution (F5) does not use the solution at all, we only care about the .csproj file. When exporting we also only care about the .csproj file, but we still have some checks for the .sln file in some places. Some of these checks are left from Godot 3 where we used to use the .sln file to build/export the C# project, nowadays we probably could remove them (or replace with checking the .csproj instead).

mrdelicate commented 3 weeks ago

The Solution Directory option, as its name implies, contains the path to the directory that contains the solution file, not the path to the file itself. So it has no way of specifying the name of the solution file, which currently is always assumed to match the project name. There's a PR to add a new option to allow configuring the name of the solution file:

Normal project execution (F5) does not use the solution at all, we only care about the .csproj file. When exporting we also only care about the .csproj file, but we still have some checks for the .sln file in some places. Some of these checks are left from Godot 3 where we used to use the .sln file to build/export the C# project, nowadays we probably could remove them (or replace with checking the .csproj instead).

Ah I went and did the fix before reading this, but I think I handled it pretty gracefully without requiring any UI updates. Easy win.

https://github.com/godotengine/godot/pull/98807