Repository: godot
Issue: MSBuild cannot access environment variables (PATH) for NuGet dependencies
Labels: bug,topic:buildsystem,topic:dotnet

### Tested versions

- Reproducible in: v4.3.stable.mono.official [77dcf97d8]

### System information

Godot v4.3.stable.mono - macOS 14.4.1 - Vulkan (Forward+) - integrated Apple M2 Pro - Apple M2 Pro (12 Threads)

### Issue description

My project has a dependency that is installed with NuGet. When I build the Godot project, this NuGet package tries to build an MSBuild target, and fails, because it cannot find `dotnet`, although `dotnet` is installed properly on my system.

### Steps to reproduce

I have created an example project with a dependency, added to the `.csproj` file:

    <PackageReference Include="FlatSharp.Compiler" Version="[7.7.0]" />

When I build the Godot project, this package tries to build an MSBuild target, and fails, because it cannot find `dotnet`. This is the output in Godot's "MSBuild" tab:

    MSB3073: The command "dotnet --list-sdks" exited with code 127. 
    /Users/theome/.nuget/packages/flatsharp.compiler/7.7.0/build/FlatSharp.Compiler.targets(98,5)

This is an excerpt from the `msbuild_log.txt`:

    Project "nuget-example.csproj" (default targets):
      Exec: dotnet --list-sdks
      Exec: /var/folders/w_/mdv4sslx3sg2_xk497c1vz5h0000gn/T/MSBuildTemptheome/tmpb99fda8e72d64fe99d946dee8fd19f35.exec.cmd: line 2: dotnet: command not found
      /Users/theome/.nuget/packages/flatsharp.compiler/7.7.0/build/FlatSharp.Compiler.targets(98,5): error MSB3073: The command "dotnet --list-sdks" exited with code 127. [/Users/theome/nuget-example/nuget-example.csproj]
    Done building project "nuget-example.csproj" -- FAILED.

This is the command in the file `FlatSharp.Compiler.targets` that tries to run `dotnet`:

    <Exec Command="dotnet --list-sdks" ConsoleToMsBuild="false">
      <Output TaskParameter="ConsoleOutput" PropertyName="StdOut" />
    </Exec>

If I modify the file and add the following command:

    <Exec Command="echo $PATH" ConsoleToMsBuild="false">
      <Output TaskParameter="ConsoleOutput" PropertyName="StdOut" />
    </Exec>

then I can see in `msbuild_log.txt` that `PATH` doesn't contain the required `dotnet` path:

    Project "nuget-example.csproj" (default targets):
      Exec: echo $PATH
      Exec: /usr/bin:/bin:/usr/sbin:/sbin

- `dotnet` is installed correctly on my machine, and I can build and run the Godot project if I don't add the dependency.
- If I build and run the project from VS Code, the build process succeeds and the game launches.
- If I open Godot from a shell with `open /Applications/Godot_mono.app/` and build and run the project from Godot, it also works.
- Setting an explicit `dotnet` path in Editor Settings at `dotnet/editor/custom_exec_path` does not solve the issue.

I would expect that the project builds without errors when I launch Godot from the Finder and then use the "Build Project" option in Godot. Would it be possible to add an Editor Setting to explicitly set environment variables for the MSBuild process?

### Minimal reproduction project (MRP)

[nuget-example.zip](https://github.com/user-attachments/files/16886607/nuget-example.zip)