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

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

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 9
  • Comments: 37 (6 by maintainers)

Most upvoted comments

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 found this to be a problem when I installed dotnet via HomeBrew on mac. Uninstalled that, then used the normal installer from https://aka.ms/dotnet-download

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

@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?

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

@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>

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.

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.

@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

@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.

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?

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

@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.

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