19

I've installed dotnet core 3 sdk and OmniSharp 1.18 extension on VSCode but OmniSharp has an error: Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.

Gama11
  • 31,714
  • 9
  • 78
  • 100
arsmn
  • 451
  • 2
  • 7
  • 12

11 Answers11

39

Try the workaround solution bellow:

Add a file called omnisharp.json to your project folder with following content

{
    "MsBuild": {
        "UseLegacySdkResolver": true
    }
}

Then restart the Visual Studio Code

Sang Au
  • 514
  • 1
  • 4
  • 5
  • Working for new projects but not for older projects update to new .net core version. Suggestions? – Varun Verma Apr 07 '19 at 09:32
  • For this case, you can add a file called "global.json" to your project folder with following content: `{ "sdk": { "version": "2.1.200" } }` The value of version key is the version of a target SDK – Sang Au Apr 12 '19 at 05:01
  • 2
    I have a dream, and in that dream OmniSharp just works every time I open VS Code without surprises coming from its updates... Btw, the `global.json` solution didn't work for me, but the `omnisharp.json` did. – amedina Nov 20 '19 at 17:49
  • Why is it that we need this why doesnt MSs code genereation doesnt generate this if it is needed -.- they cant even make hello world work – Dživo Jelić Jan 18 '20 at 13:07
11

If you're on Linux or Mac, add the path to your sdk folder in your .bashrc (or wherever else you want):

export MSBuildSDKsPath=$HOME/soft/dev/dotnet/sdk/3.0.100-preview3-010431/Sdks

The same behavior can also be solved with this command: dotnet nuget locals all -c

Olivia Stork
  • 4,660
  • 5
  • 27
  • 40
Evgy
  • 386
  • 1
  • 3
  • 10
7

The answer by Evgy will work specifically with .NET Core Preview 3, but if you want the fix to work with the released version of .NET Core 3.0 or higher, then you can add the following line to your .bashrc file (supposing you are on Linux):

export MSBuildSDKsPath="/usr/share/dotnet/sdk/$(dotnet --version)/Sdks"
Neits
  • 319
  • 3
  • 10
  • This is the best answer for non-Ubuntu (non-Mint etc) Linux, or if you installed the SDKs using something other than snap. If you used snap, however, your SDKs will be here: /snap/dotnet-sdk/current/sdk/$(dotnet --version)/Sdks . Use the same export as above, but this ~/snap path instead. Browse there, or the /usr/share... path above and look for the SDK, then add the appropriate export to your bash startup file (.bashrc). – IdahoB Jan 28 '21 at 13:40
5

I have this problem and none of the above answers worked for me, I don't know why this happens but I found a little trick to fix this problem.

open your terminal and go to your project directory and execute this command

code .

yes! opening vscode from terminal fix this problem for me

Mahdi mehrabi
  • 1,486
  • 2
  • 18
  • 21
4

I had this problem with DotNet Core 3.0 and VS Code. The intellisense was not working for me.

I had an installation of Visual Studio 2019 which caused Omnisharp to get MsBuild from the following location:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin

Following some answers on Omnisharp GitHub, I installed Visual Studio Build Tools 2019 from the following link: https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16

To prevent Omnisharp from getting MsBuild from the former path, I renamed MsBuild folder to MsBuild.disabled so that the path becomes:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild.disabled\Current\Bin

Now, when I restard VS Code, Omnisharp gets MsBuild from the path C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin instead of the former path. The error is gone and intellisense works fine now.

Nimish David Mathew
  • 2,958
  • 6
  • 29
  • 45
  • 1
    I know it has been voted down, but frankly this was the only option that resolved the error for me. – Doug Dec 29 '19 at 12:00
  • I wonder if `UseLegacySdkResolver` solves this too and I am interested if VS 2019 causes the issue. There are a lot of similar issues on github it is hard to follow – KCD Jul 22 '20 at 01:12
2

You need to install ".Net Core build tools" from the Visual Studio installer, as described here - https://github.com/OmniSharp/omnisharp-roslyn/issues/1311#issuecomment-428361674

Can also be installed with chocolatey:

choco install visualstudio2017-workload-netcorebuildtools
nZeus
  • 2,475
  • 22
  • 21
1
  • It should be v1.18.0-beta7 at this time: https://github.com/OmniSharp/omnisharp-vscode/releases
  • Also if you are just using your old projects, try to add an appropriate global.json file to their root, by issuing dotnet new globaljson --sdk-version 2.2.100 command. Otherwise they will use the .NET Core 3x SDK by default. If you do have a global.json, check its content and make sure you are using a correct version. You can find the installed versions using the dotnet --list-sdks command.
  • It's better to report your issue here so they can fix it for the next beta version.
VahidN
  • 18,457
  • 8
  • 73
  • 117
1

Neits solution for Ubuntu [20.04] Snap users.

echo 'export MSBuildSDKsPath="/snap/dotnet-sdk/current/sdk/$(dotnet --version)/Sdks"' >> ~/.bashrc
source ~/.bashrc
echo $MSBuildSDKsPath
tanda8
  • 61
  • 1
  • 1
  • 4
  • WORKED GREAT! This is also the solution for Mint Linux 20.1. The issue is that snap does not install the SDKs in the /usr/share/dotnet/sdk/$(dotnet --version)/Sdks location, but INSTEAD installs them into the /snap/... path shown above. The 3 commands above adds the export to your bash shell startup file so that the $MSBuildSDKsPath env variable is exported every time you start up your shell. The OmbniSharp warning/error that says the .csproj file is invalid, and complains that no SDKs could be found GOES AWAY! – IdahoB Jan 28 '21 at 13:30
0

on the global.json file inside the project make sure that the sdk version is the same as the one you have installed on the system.

MikiEthiopia
  • 129
  • 1
  • 1
  • 5
0

that might be extremely stupid but after a couple hours of googling this problem I gave up and just coded my own build task to call dotnet build instead of msbuild into tasks.json:

        {
            "label": "build",
            "type": "shell",
            "command": "dotnet",
            "args": [
                "build",
            ],
            "group": "build",
            "presentation": {
                "reveal": "silent"
            },
            "problemMatcher": "$msCompile"
        }

and here is my launch config from launch.json:

        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/bin/Debug/net5.0/${workspaceFolderBasename}.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal",
            "stopAtEntry": false
        }

It might not be a correct way to do this but it lets me run my code and use all the functions of the debugger, so I guess it's good enough.

Igor Gunin
  • 173
  • 7
0

The only thing that worked for me was quitting VSCode (I'm on a Mac) and reinstalling the .NET SDK.

Steve Brush
  • 2,911
  • 1
  • 23
  • 15