microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
228 stars 12 forks source link

[BUG] C# Dev Kit Cannot Locate Installed .NET Core 8 SDK on MacOS #1527

Open TotalChris opened 6 days ago

TotalChris commented 6 days ago

Describe the Issue

After a lot of troubleshooting, I've decided to post this here. When opening a .NET Core 8 project in VSCode with the C# Dev Kit extension installed, I receive errors that the SDK cannot be located. This is the full output from the extension:

Starting opening a solution...
Starting processing the solution file "/Users/chaueisen-yates/Projects/Online Banking/WebE2E/WebE2E.sln" in Dev Kit server...
Failed to find dotnet from path with "which dotnet".
Cannot find .NET SDK installation from PATH environment. C# DevKit extension would not work without a proper installation of the .NET SDK accessible through PATH environment. Rebooting might be necessary in some cases. Check the PATH environment logged in the C# DevKit logging window. In some cases, it could be affected how VS code was started.
PATH=/usr/bin:/bin:/usr/sbin:/sbin
Using local .NET runtime at "/Users/chaueisen-yates/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/8.0.10~arm64~aspnetcore/dotnet"
.NET server started and IPC established in 545ms
Completed Spawn .NET server (975ms)
Completed processing the solution file "/Users/chaueisen-yates/Projects/Online Banking/WebE2E/WebE2E.sln" in Dev Kit server (1153ms)
Starting restoring NuGet packages...
Selected configuration: <Default>, active configuration: Debug|Any CPU
Completed opening a solution (1157ms)
Starting command: "dotnet" restore /Users/chaueisen-yates/Projects/Online Banking/WebE2E/WebE2E.sln --interactive...
Failed to monitor project loading status.
Starting Query for all projects...
Failed at 'Query for all projects' (39ms) with error: Error: Exception while talking to proxy: Error: One or more errors occurred. (No installed .NET SDK was found on the computer. If it is installed, make sure it can be found through the PATH environment variable.)

The issue in this case is that the correct PATH variable is not being found or used by the extension process. In my case, I'm running MacOS Sonoma (Latest) and VSCode Release. I did try a fresh install of VSCode Insiders and only installed the C# Dev Kit extension, but the PATH came back the same as above.

My PATH, when queried from a fresh MacOS Terminal is:

~ % echo $PATH  
/Users/chaueisen-yates/.nvm/versions/node/v10.24.1/bin:/usr/local/bin:/usr/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/usr/local/share/dotnet:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/chaueisen-yates/.rvm/bin:/usr/share/bin/dotnet:/Users/chaueisen-yates/.nvm

This happens when opening VSCode from the Dock in MacOS. As I understand it, VSCode does not necessarily provide the correct path unless spawned from a terminal process which carries that PATH, i.e from the code command. Opening my project this way resolves the issue, however it is not the solution in my opinion.

This may be a greater underlying issue with VSCode as a whole, but there is seemingly no clear-cut way to override the DevKit extension's SDK locating mechanism. I have added and tweaked custom SDK path overrides to most of the different places you can do so in C# DevKit, C#, and .NET Install Tool's settings pages and no combination of these override the PATH being used or the result of the locating process

Regardless of if this is an issue with the extension or if it's an issue to be taken up with the VSCode project, I would think any settings overrides would supersede the default "which dotnet" behavior.

Steps To Reproduce

  1. Install the latest .NET Core SDK from the installer on the website
  2. Install VSCode on MacOS via the download on the website
  3. Open VSCode and install the C# DevKit Extension
  4. Open a .NET Core project folder
  5. Error shown above populates the C# DevKit output

Expected Behavior

  1. I would expect either VSCode to provide, or C# DevKit to locate, the correct PATH variable with the .NET Core SDK in it
  2. If that fails, I would expect C# DevKit to either use existing override settings or create a newer unified override setting for finding the SDK.

Environment Information

nagilson commented 2 days ago

Adding @lifengl for SDK lookup logic, but I agree that vscode does not always get the correct PATH and most likely we would want to raise a bug on the vscode side as I dont see any other escapes here.