Bogey
Bogey

Reputation: 5734

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

I'm using Visual Studio Code. On my machine, I have two separate installations of the Net Core SDK / dotnet CLI tools

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.

  1. 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?
  2. Any particular configuration setting or similiar?

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

Upvotes: 13

Views: 42608

Answers (6)

Pui Ho Lam
Pui Ho Lam

Reputation: 230

According to the Github issue

Setting "dotnet.dotnetPath" in settings.json will now allow C# dev kit to use the specified dotnet folder.

Do note that unlike "dotnetAcquisitionExtension.existingDotnetPath", it is path to the folder not the exe.

EDIT: I believe OmniSharp is now replaced by Dev C# and the setting to do this is kind of obscure and not easy to find. So, I will leave this answer remain open

Upvotes: 0

alokym
alokym

Reputation: 101

For Linux users who run vscode via a desktop file (or via a shortcut on the panel and so on).

  1. Copy the shortcut file from the system directory to your own one. This step preserves your changes after updating vscode to newer versions (your path may be different, it depends on OS):
cp /usr/share/applications/code.desktop ~/.local/share/applications/
  1. Edit .desktop file and replace
Exec=/usr/share/code/code --unity-launch %F

with

Exec=bash -c "PATH=$HOME/.dotnet:$HOME/.dotnet/tools:$PATH /usr/share/code/code --unity-launch %F"

where PATH=$HOME/.dotnet is the path to my SDK installation, change it if your path is different

  1. *(optional some desktop environments can do this for you) Place this file into your desktop, panel or find/place it in the menu.

Upvotes: 0

moly
moly

Reputation: 433

I found another workaround that doesn't require running through a bat file.

Add this to your settings.json, with your sdk path:

"terminal.integrated.env.windows": {
    "PATH": "C:\\Users\\Name\\AppData\\Local\\Programs\\dotnet;${env:PATH}"
}

Then in your project's .vscode/tasks.json, change the type of any task using dotnet from "process" to "shell", and in your .vscode/launch.json add "console": "integratedTerminal" to the "configurations" section.

Upvotes: 0

Atiq Ur Rehman Qazi
Atiq Ur Rehman Qazi

Reputation: 3

1 - install respective .Net SDK (click on get sdk)
2 - install respective .Net developer pack (see from output logs)
3 - close vscode
4 - open VSCode from terminal/cmd usin "code" command

Upvotes: 0

user1930469
user1930469

Reputation: 344

Following Bogey's lead of 2018-02-16, and after manually installing the SDK per https://learn.microsoft.com/en-us/dotnet/core/install/windows?tabs=netcore31#download-and-manually-install, when I was then following the tutorial at https://learn.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.

Upvotes: 5

Bogey
Bogey

Reputation: 5734

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

Upvotes: 2

Related Questions