godotengine / godot

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

MSBuild cannot access environment variables (PATH) for NuGet dependencies #96596

Open Theome opened 2 weeks ago

Theome commented 2 weeks ago

Tested versions

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

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

bruvzg commented 2 weeks ago

macOS apps do not use shell environment (same issue as https://github.com/godotengine/godot/issues/96409), should be fixed by https://github.com/godotengine/godot/pull/81266