VS Code / OmniSharp - how to set path to dotnet SDK / CLI tools explicitly

12,548

Solution 1

Have found a bit of a workaround now, I've created a bat to start Visual Studio Code, in which I override the PATH environment variable upon execution and remove the outdated path.

This works for me now, but I'll leave this open in case there is a better solution such as a direct config of OmniSharp or such

Solution 2

Following Bogey's lead of 2018-02-16, and after manually installing the SDK per https://docs.microsoft.com/en-us/dotnet/core/install/windows?tabs=netcore31#download-and-manually-install, when I was then following the tutorial at https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code I kept getting messages popping up or in the Visual Studio Code's terminal saying something like

It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
      https://aka.ms/dotnet-download

But with a batch file in which I set the PATH environment variable before then starting Code, I am able to run the commands in the tutorial, eg, dotnet new console, successfully.

The batch file I created sets the PATH to be as it normally would (ie, as revealed by running echo %PATH% at a command prompt), but with references to SDKs not installed manually by me removed and with a reference to the SDK I installed manually added. Roughly:

set PATH=C:\Program Files (x86)\various\things;C:\WINDOWS\other\things;C:\Users\user1930469\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\user1930469\my_manually_installed_sdk\dotnet
start "" "C:\Users\user1930469\AppData\Local\Programs\Microsoft VS Code\Code.exe"
exit

With Visual Studio Code then open, I can confirm the value of the PATH variable in Code's terminal with

$env:path

and successfully run commands like

dotnet --help

Thanks for the tip, Bogey.

Share:
12,548
Bogey
Author by

Bogey

Updated on July 13, 2022

Comments

  • Bogey
    Bogey almost 2 years

    I'm using Visual Studio Code. On my machine, I have two separate installations of the Net Core SDK / dotnet CLI tools; an outdated version (netcore 1.1) in the standard path (%ProgramFiles%\dotnet); and a recent version (netcore 2.0) installed to a different, custom path (%AppData%...)

    I need Visual Studio Core - and thereby, Omnisharp - to use the recent, i.e. custom installation. Unfortunately, due to my machine setup, the default "dotnet" command is registered with the out of date installation, and I cannot change this. Omnisharp is using the SDK from the same location as well.

    Now, is there any way for a non-admin user to specify in Visual Studio Code / Omnisharp to use the dotnet tools from my custom location? Any particular configuration setting or similar?


    For context, as to why my machine has such a weird setup and why I cannot do much about it, see Cmd precedence: How to use correct dotnet.exe when installed in 2 locations?

    Thanks

  • user1930469
    user1930469 almost 4 years
    Thanks for self-answering, Bogey. Could you please share the contents of the bat so we can see how start VS Code with an overridden PATH? Thanks in advance.
  • Chris Wolf
    Chris Wolf over 2 years
    For MacOS, let's say your custom location is /opt/dotnet-sdk - you could do: export PATH="/opt/dotnet-sdk:$PATH" open -a /Applications/Visual\ Studio\ Code.app (sorry, don't know how to force newlines in SO comments)