Omnisharp-vscode: The SDK 'Microsoft.NET.Sdk' specified could not be found.

Created on 24 Mar 2019  路  36Comments  路  Source: OmniSharp/omnisharp-vscode

Couldn't get the (latest) C# extension to work correctly on one of my machines. The project is a .NET Core 3.0 dotnet new console project with no changes.

Here are the logs: https://gist.github.com/richlander/9931ebb3c3570615439fe0ccf3ae6657

The logs demonstrate the machine env, launch code and then show the O# logs that I saw, rinse and repeat. I tried various suggestions I found @ https://github.com/Microsoft/msbuild/issues/2532

.Net sdk not found

Most helpful comment

Don't ask me where I found this, but the following command has fixed the issue for me (probably worth a try):

dotnet nuget locals all -c

I also have added this to my omnisharp.json:

"MsBuild":
{
    "UseLegacySdkResolver": true
}

Gold luck

All 36 comments

From the logs this appears to be the same issue of msbuild 15.x being incompatible with .NET Core SDK 3.0 according to the resolver. I believe this is tracked by #2876. cc @rchande

More meta, it turns out that O# needs to carry the 16.x version of either the resolver or msbuild in order to correctly work with .NET Core 3.0. This is only a problem on machines without VS 16 (which is a lot of cases). We're hoping to get this fixed in the same timeframe as .NET Core 3.0 Preview 4.

Same problem here:

````
.NET Core SDK (reflecting any global.json):
Version: 2.1.602
Commit: 04475eb7cf

Runtime Environment:
OS Name: linuxmint
OS Version: 19.1
OS Platform: Linux
RID: linux-x64
Base Path: /usr/share/dotnet/sdk/2.1.602/

Host (useful for support):
Version: 2.1.9
Commit: dcedc87d22

.NET Core SDKs installed:
2.1.602 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.9 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.9 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
````

For me this is a massive problem, as I use my Linux machine for my C# teaching.
Probably better to revert the last update...

Don't ask me where I found this, but the following command has fixed the issue for me (probably worth a try):

dotnet nuget locals all -c

I also have added this to my omnisharp.json:

"MsBuild":
{
    "UseLegacySdkResolver": true
}

Gold luck

@zeroskyx , where did you find the omnisharp.json file? Thanks

EDIT1: ~/.omnisharp/

EDIT2: did not solve it...

@zeroskyx , where did you find the omnisharp.json file? Thanks

EDIT1: ~/.omnisharp/

EDIT2: did not solve it...

&

Couldn't get the (latest) C# extension to work correctly on one of my machines. The project is a .NET Core 3.0 dotnet new console project with no changes.

Here are the logs: https://gist.github.com/richlander/9931ebb3c3570615439fe0ccf3ae6657

The logs demonstrate the machine env, launch code and then show the O# logs that I saw, rinse and repeat. I tried various suggestions I found @ Microsoft/msbuild#2532

this did the trick for me:
https://github.com/OmniSharp/omnisharp-vscode/issues/2876#issuecomment-480547334

As well: https://github.com/OmniSharp/omnisharp-vscode/issues/2965#issuecomment-480262373

Plenty others reported this as a valid fix. MSs .net 2.2.203 and later don't work with latest omnibox.
Downgrading .net SDK to 2.2.105 did the trick for me. I had some issues with downgrading, i had to reinstall, then it started working. i've been on this fix for the whole day (not exaggerating) so i'm not sure what made it downgrade but downgrading was the key. 2.2.105 was the answer for me.

This is resolved for me with this release: https://github.com/OmniSharp/omnisharp-vscode/releases/tag/v1.19.0-beta1

Please try it (or a later release), and share if that resolves the problem for you.

@richlander The issue does still happen in latest version 1.19.1. I created a new program with dotnet new console and loaded the directory in vscode.

OmniSharp Log:

[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file <path-to-project>
Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk' specified could not be found.  <path-to-project>
  at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject (System.String errorSubCategoryResourceName, Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, System.Object[] args) [0x00040] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject[T1] (System.Boolean condition, System.String errorSubCategoryResourceName, Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, T1 arg0) [0x00003] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1] (Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, T1 arg0) [0x00000] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].ExpandAndLoadImportsFromUnescapedImportExpressionConditioned (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement, System.Collections.Generic.List`1[Microsoft.Build.Construction.ProjectRootElement]& projects, Microsoft.Build.BackEnd.SdkResolution.SdkResult& sdkResult, System.Boolean throwOnFileNotExistsError) [0x0024e] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].ExpandAndLoadImports (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement, Microsoft.Build.BackEnd.SdkResolution.SdkResult& sdkResult) [0x00027] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].EvaluateImportElement (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement) [0x0000d] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].PerformDepthFirstPass (Microsoft.Build.Construction.ProjectRootElement currentProjectOrImport) [0x000e6] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].Evaluate (Microsoft.Build.BackEnd.Logging.ILoggingService loggingService, Microsoft.Build.Framework.BuildEventContext buildEventContext) [0x00103] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].Evaluate (Microsoft.Build.Evaluation.IEvaluatorData`4[P,I,M,D] data, Microsoft.Build.Construction.ProjectRootElement root, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, System.Int32 maxNodeCount, Microsoft.Build.Collections.PropertyDictionary`1[T] environmentProperties, Microsoft.Build.BackEnd.Logging.ILoggingService loggingService, Microsoft.Build.Evaluation.IItemFactory`2[S,T] itemFactory, Microsoft.Build.Evaluation.IToolsetProvider toolsetProvider, Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache, Microsoft.Build.Framework.BuildEventContext buildEventContext, Microsoft.Build.BackEnd.SdkResolution.ISdkResolverService sdkResolverService, System.Int32 submissionId, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x0002d] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Project.Reevaluate (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x0005e] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00035] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00000] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary (Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00007] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Project.Initialize (System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, System.String subToolsetVersion, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00126] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, System.String subToolsetVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00093] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, System.String subToolsetVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x00000] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x00000] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection) [0x00000] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.ProjectCollection.LoadProject (System.String fileName, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion) [0x000f7] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at Microsoft.Build.Evaluation.ProjectCollection.LoadProject (System.String fileName, System.String toolsVersion) [0x00000] in <4e0a1f1d78cf4c1ebd6f9a3dbcebf3bb>:0 
  at OmniSharp.MSBuild.ProjectLoader.EvaluateProjectFileCore (System.String filePath) [0x0003f] in <69148e098afe4042aa56606d5bafd188>:0 
  at OmniSharp.MSBuild.ProjectLoader.BuildProject (System.String filePath) [0x0000d] in <69148e098afe4042aa56606d5bafd188>:0 
  at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Load (System.String filePath, OmniSharp.MSBuild.ProjectIdInfo projectIdInfo, OmniSharp.MSBuild.ProjectLoader loader) [0x00015] in <69148e098afe4042aa56606d5bafd188>:0 
  at OmniSharp.MSBuild.ProjectManager+<>c__DisplayClass30_0.<LoadProject>b__0 () [0x00000] in <69148e098afe4042aa56606d5bafd188>:0 
  at (wrapper delegate-invoke) System.Func`1[System.ValueTuple`3[OmniSharp.MSBuild.ProjectFile.ProjectFileInfo,System.Collections.Immutable.ImmutableArray`1[OmniSharp.MSBuild.Logging.MSBuildDiagnostic],OmniSharp.MSBuild.Notification.ProjectLoadedEventArgs]].invoke_TResult()
  at OmniSharp.MSBuild.ProjectManager.LoadOrReloadProject (System.String projectFilePath, System.Func`1[TResult] loader) [0x0001b] in <69148e098afe4042aa56606d5bafd188>:0 

[fail]: OmniSharp.MSBuild.ProjectManager
        Attempted to update project that is not loaded: <path-to-project>

My project file looks like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

</Project>

@MaxXor I suddenly got the exact same error today, when it was working fine before. I was eventually able to fix it by installing Visual Studio Community 2019. Instead of using MSBuild Visual Studio Community 2017 15.9.28307.280, it detected Visual Studio Community 2019 16.1.28917.181 and now it works again.

Note, I tried installing older omnisharp versions but it had no effect (1.19.1 to 1.19 and then 1.18)

@Doeke Sadly that doesn't work for me on Linux...

Don't ask me where I found this, but the following command has fixed the issue for me (probably worth a try):

dotnet nuget locals all -c

I also have added this to my omnisharp.json:

"MsBuild":
{
  "UseLegacySdkResolver": true
}

Gold luck

Just running the "dotnet nuget locals all -c" worked for me

I still get this error when creating new projects with dotnet new console on Windows 10.

Edit

This did not work for me:

Don't ask me where I found this, but the following command has fixed the issue for me (probably worth a try):
dotnet nuget locals all -c
I also have added this to my omnisharp.json:

"MsBuild":
{
    "UseLegacySdkResolver": true
}

Gold luck

Just running the "dotnet nuget locals all -c" worked for me

Installing Visual Studio 2019 and opening my .sln in Visual Studio 2019 fixed the problem for me.

I tried this on a new macOS machine and did not run into this problem with the latest 3.0 preview and VS Code. If anyone is still having this problem, can you provide a detailed description of your environment?

I have the same problem on Ubuntu 19.04, using dotnet 3.0.100-preview7-012821.
I made a project using dotnet new webapi and opened it in VSCode.

Here are the logs and system info:
https://gist.github.com/TheSimpleZ/27a8f1de06c52fe6223f7116714a941d

@TheSimpleZ From the logs, your sdk was installed via snap and we have an issue with SDK resolution there.

https://github.com/dotnet/cli/issues/12110 tracks the fix

https://github.com/OmniSharp/omnisharp-vscode/issues/3160#issuecomment-517057835 has a workaround.

@nguerrera Thank you! Now it works well.

I got this problem today with the latest VS Code installed on Manjaro (visual-studio-code-bin 1.36.1-1 I believe). I also ran into this issue last week on Arch Linux; installing msbuild 16+ solved it.

I'm on Windows 10 1903, install vs-code. Noticed when you create your first program it stores it in the the users root directory folder. if you move it from this folder you'll need to clear local resources (cache).

Using the command above : dotnet nuget locals all -c

once I did that I could then run my app which I placed in Documents folder. This resolved all output issues in vs-code.

Thx

I'm on gentoo and wanted to try new .net core 3.0. I downloaded sdk in .tar.gz file and extracted it to /usr/share/dotnet. Then I manually created symlink /usr/bin/dotnet to /usr/share/dotnet/dotnet. After this, dotnet --version, dotnet new console and dotnet run works as expected. Ionide-FSharp (that uses OmniSharp) also works fine for F# project. But in C# project I get this error. I have no mono nor msbuild installed. VS Code 1.38.1 installed through dotnet overlay (.netcore 3.0 is not available in overlay yet). So, this problem is not related to snap or particular distro, it happens when installing manually too.

I found workaround in #2816 that works for me:
export MSBuildSDKsPath=/usr/share/dotnet/sdk/3.0.100/Sdks
and starting vscode from that terminal session.

But why OmniSharp fails to resolve SDK by itself while dotnet build can? Why it works in F# project?

Don't ask me where I found this, but the following command has fixed the issue for me (probably worth a try):

dotnet nuget locals all -c

I also have added this to my omnisharp.json:

"MsBuild":
{
  "UseLegacySdkResolver": true
}

Gold luck

I just upgraded to dotnet core 3.0 on MacOS and OmniSharp failed to load my projects. Setting the UseLegacySdkResolver to true worked for me :)

I uninstalled 'Remote - WSL' extension. maybe SDK-Path problem (where to set in VScode?)

I'm having this problem with the dotnet core 3.0 full release, and omnisharp 1.34.4-beta.23 on ubuntu 18.04 :(

@trampster

you could try adding omnisharp.json file:

{
   "MSBuild": {
       "UseLegacySdkResolver": true
   }
}

and see if it helps. If it doesn't please post your OmniSharp log.

where is omnisharp.json?
my ~/.omnisharp/ folder is empty... should it be?
I created the omnisharp.json file and it fixed the problem.

I assume this means that the current SdkResolver is broken... is there a fix coming? when is it safe to remove the UseLegacySdkResolver setting?

I see that this issue is closed, but clearly is still happening using the latest version, can it please be reopened?

dotnet/cli#12110 is not relevant for me, my sdk was not installed via snap.

I have a suspicion that up until now all your ubuntu users using dotnet core 3.0 were using the snap package because Microsoft doesn't provide deb packages for previews, now that the full release is out, could it be that you had a non snap related issue all along but no one noticed because no one could test it...

Well the full release is out it, uses debs not snaps and it's broken please reopen.

Here is my dotnet --info showing that I am not using the snap sdk

.NET Core SDK (reflecting any global.json):
Version: 3.0.100
Commit: 04339c3a26

Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /usr/share/dotnet/sdk/3.0.100/

Host (useful for support):
Version: 3.0.0
Commit: 95a0a61858

.NET Core SDKs installed:
3.0.100 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

Having the same problem on Windows 10 with Omnisharp v1.34.3 and .NET Core 3.0. Adding "UseLegacySdkResolver": true to my omnisharp.json file fixed the issue.

I'm on gentoo and wanted to try new .net core 3.0. I downloaded sdk in .tar.gz file and extracted it to /usr/share/dotnet. Then I manually created symlink /usr/bin/dotnet to /usr/share/dotnet/dotnet.
But why OmniSharp fails to resolve SDK by itself while dotnet build can? Why it works in F# project?

I was having the same problem on Linux Solus 4.1.

I manually installed dotnet in /opt/dotnet, and creating a symlink to /usr/bin/dotnet fixed it for me.

Obviously OmniSharp has hardcoded a path somewhere instead of abiding by $DOTNET_ROOT or $PATH.

Having the same problem on Windows 10 with Omnisharp v1.34.3 and .NET Core 3.0. Adding "UseLegacySdkResolver": true to my omnisharp.json file fixed the issue.

Also worked for me!

Having the same problem on Windows 10
Adding "UseLegacySdkResolver": true to my omnisharp.json file fixed the issue.

Fixed for me too.

File location on Windows is C:\Users\%USERNAME%\.omnisharp\. The folder was empty in my case so just created omnisharp.json

This issue should be reopened, as it's still happening as of today. If the legacy SDK resolver can find the correct SDK, then why does the current one have issues?

@adam-becker the root cause of the issues with the 3.1.401 SDK is that it has a minimum MSBuild version of 16.7. The current stable and preview Mono releases only include 16.6.

Please try the 1.23.0 pre-release build (https://github.com/OmniSharp/omnisharp-vscode/releases/tag/v1.23.0) of the C# extension as it ships with a custom package of Mono and MSBuild that is a supported version. Note you may need to set "useGlobalMono" to "never" so that the included Mono is used instead of a system install.

MSBuildSDKsPath

Having the same problem on Windows 10
Adding "UseLegacySdkResolver": true to my omnisharp.json file fixed the issue.

Fixed for me too.

File location on Windows is C:\Users\%USERNAME%\.omnisharp\. The folder was empty in my case so just created omnisharp.json

This is still an issue though. It should work without the Legacy SDK Resolver. As far as I know, only workarounds have been proposed, not a proper fix.

@niikoo if you are having troubles, please post your log and open a new issue. There are plenty of unrelated reasons that can cause the SDK to not be found - depending on the combination of OS, SDK version, OmniSharp configuration, usage of global vs local Mono and so on. Additionally, the SDK is a moving target because the minimal MSBuild requirement keeps changing so OmniSharp has to constantly be playing catch up game.

For example the original reason why this issue was opened has been addressed by moving to newer bundled MSBuild

Was this page helpful?
0 / 5 - 0 ratings