Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk' specified could not be found. #1849

Closed
cjaeckel opened this issue Nov 9, 2017 · 28 comments

Comments

@cjaeckel
Copy link

cjaeckel commented Nov 9, 2017

Environment data

dotnet --info
.NET Command Line Tools (1.0.1)

Product Information:
 Version:            1.0.1
 Commit SHA-1 hash:  005db40cd1

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15063
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.1

(No Visual Studio)

VS Code version:
1.18.0
C# Extension version:
ms-vscode.csharp-1.13.0

Steps to reproduce

Start OmniSharp server
(On VS Code startup or Restart OmniSharp)

Expected behavior

OmniSharp server starts and loads all project files.

Actual behavior

[warn]: OmniSharp.MSBuild.MSBuildProjectSystem
        Failed to load project file 'd:\my-proj\app-server\src\DMProg.Core\DMProg.Core.csproj'.

See OmniSharp log:

Starting OmniSharp server at 11/9/2017, 12:52:40 PM
    Target: d:\my-proj\app-server

OmniSharp server started
    Path: D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\OmniSharp.exe
    PID: 9296

[dbug]: OmniSharp.MSBuild.Discovery.Providers.VisualStudioInstanceProvider
        An exception was thrown while retrieving Visual Studio instances.
System.DllNotFoundException: Unable to load DLL 'Microsoft.VisualStudio.Setup.Configuration.Native.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at OmniSharp.MSBuild.Discovery.Interop.GetSetupConfiguration(ISetupConfiguration& configuration, IntPtr reserved)
   at OmniSharp.MSBuild.Discovery.Interop.GetSetupConfiguration()
   at OmniSharp.MSBuild.Discovery.Providers.VisualStudioInstanceProvider.GetInstances()
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 15.0 - "D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to 'D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 15.0 - "D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin"
            CscToolExe = csc.exe
            CscToolPath = D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Roslyn
            MSBuildExtensionsPath = D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild
            MSBuildToolsPath = D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Resolved 'Microsoft.Build.Framework' to 'D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Microsoft.Build.Framework.dll'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.CodeAnalysis.VisualBasic.Workspaces, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.CodeAnalysis.VisualBasic.Features, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in 'd:\my-proj\app-server'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Initializing in d:\my-proj\app-server
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Auto package restore: False
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Update workspace context
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Resolving projects references
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.Build'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Resolved 'Microsoft.Build' to 'D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Microsoft.Build.dll'
[dbug]: OmniSharp.MSBuild.MSBuildProjectSystem
        MSBuild environment: 
Mode: Standalone
RunningTests: False
RunningInVisualStudio: False
MSBuildToolsDirectory32: D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin
MSBuildToolsDirectory64: D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin
MSBuildSDKsPath: C:\Program Files\dotnet\sdk\1.0.1
CurrentMSBuildConfigurationFile: D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\MSBuild.exe.config
CurrentMSBuildExePath: D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\MSBuild.exe
CurrentMSBuildToolsDirectory: D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin
VisualStudioInstallRootDirectory: 
MSBuildExtensionsPath: D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin

[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        No solution files found in 'd:\my-proj\app-server'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Resolved 'Microsoft.Build' to 'D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Microsoft.Build.dll'
[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Loading project: d:\my-proj\app-server\src\DMProg.Core\DMProg.Core.csproj
[dbug]: OmniSharp.MSBuild.ProjectFile.ProjectFileInfo
        'MSBuildExtensionsPath' set to 'D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild'
[dbug]: OmniSharp.MSBuild.ProjectFile.ProjectFileInfo
        'CscToolPath' set to 'D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Roslyn'
[dbug]: OmniSharp.MSBuild.ProjectFile.ProjectFileInfo
        'CscToolExe' set to 'csc.exe'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.Build.resources, Version=15.1.0.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.Build.resources, Version=15.1.0.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a'
[warn]: OmniSharp.MSBuild.MSBuildProjectSystem
        Failed to load project file 'd:\my-proj\app-server\src\DMProg.Core\DMProg.Core.csproj'.
d:\my-proj\app-server\src\DMProg.Core\DMProg.Core.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk' specified could not be found.  d:\my-proj\app-server\src\DMProg.Core\DMProg.Core.csproj
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List`1& projects, Boolean throwOnFileNotExistsError)
   at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(ILoggingService loggingService, BuildEventContext buildEventContext)
   at Microsoft.Build.Evaluation.Project.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.Project.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion)
   at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.LoadProject(String filePath, String solutionDirectory, ILogger logger, MSBuildInstance msbuildInstance, MSBuildOptions options, ICollection`1 diagnostics, ImmutableArray`1& targetFrameworks)
   at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Create(String filePath, String solutionDirectory, ILogger logger, MSBuildInstance msbuildInstance, MSBuildOptions options, ICollection`1 diagnostics)
   at OmniSharp.MSBuild.MSBuildProjectSystem.LoadProject(String projectFilePath)

@cjaeckel
Copy link
Author

cjaeckel commented Nov 9, 2017

Sorry I need to update my issue report.
The OmniSharp log above was produced with an environment set to an obvious wrong location.
When setting

MSBuildSDKsPath=C:\Program Files\dotnet\sdk\1.0.1\Sdks

it is working.

BUT with out any MSBuildSDKsPath being set it defaults to the non existing path

D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Sdks

and the mentioned error occurs.

So, it seems to be required to explicitly set the environment MSBuildSDKsPath (correctly) in order to get OmniSharp to run with version 1.13.0

This was not necessary with previous versions.

@DustinCampbell
Copy link
Member

Thanks for the detailed information. Could you check D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\omnisharp\msbuild\15.0\Bin\ and let me know if there is an SdkResolvers folder there?

@cjaeckel
Copy link
Author

cjaeckel commented Nov 9, 2017

Yes, I can confirm that there is a SdkResolvers folder (containing a Microsoft.DotNet.MSBuildSdkResolver...).

@DustinCampbell
Copy link
Member

Thanks! Without MSBuildSDKsPath set, could you set COREHOST_TRACE=1 and load your project is VS Code? This should add spew a bit of diagnostics in your OmniSharp Log when the SdkResolver tries to locate your SDK.

@cjaeckel
Copy link
Author

cjaeckel commented Nov 9, 2017

Okay, I added COREHOST_TRACE=1 and removed MSBuildSDKsPath.
When now loading the project the probing for the SDK path seems to happen after the actual project load:

Starting OmniSharp server at 11/9/2017, 4:24:32 PM
    Target: D:\my-proj\DMProg\app-server

OmniSharp server started
    Path:D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\OmniSharp.exe
    PID: 9308

[dbug]: OmniSharp.MSBuild.Discovery.Providers.VisualStudioInstanceProvider
        An exception was thrown while retrieving Visual Studio instances.
System.DllNotFoundException: Unable to load DLL 'Microsoft.VisualStudio.Setup.Configuration.Native.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at OmniSharp.MSBuild.Discovery.Interop.GetSetupConfiguration(ISetupConfiguration& configuration, IntPtr reserved)
   at OmniSharp.MSBuild.Discovery.Interop.GetSetupConfiguration()
   at OmniSharp.MSBuild.Discovery.Providers.VisualStudioInstanceProvider.GetInstances()
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 15.0 - "D:\User\Christian Jäckel\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to 'D:\User\Christian Jäckel\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 15.0 - "D:\User\Christian Jäckel\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin"
            CscToolExe = csc.exe
            CscToolPath =D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Roslyn
            MSBuildExtensionsPath =D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild
            MSBuildToolsPath =D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Resolved 'Microsoft.Build.Framework' to 'D:\User\Christian Jäckel\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Microsoft.Build.Framework.dll'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.CodeAnalysis.VisualBasic.Workspaces, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.CodeAnalysis.VisualBasic.Features, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in 'D:\my-proj\DMProg\app-server'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Initializing in D:\my-proj\DMProg\app-server
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Auto package restore: False
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Update workspace context
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Resolving projects references
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.Build'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Resolved 'Microsoft.Build' to 'D:\User\Christian Jäckel\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Microsoft.Build.dll'
[dbug]: OmniSharp.MSBuild.MSBuildProjectSystem
        MSBuild environment: 
Mode: Standalone
RunningTests: False
RunningInVisualStudio: False
MSBuildToolsDirectory32:D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin
MSBuildToolsDirectory64:D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin
MSBuildSDKsPath:D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Sdks
CurrentMSBuildConfigurationFile:D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\MSBuild.exe.config
CurrentMSBuildExePath:D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\MSBuild.exe
CurrentMSBuildToolsDirectory:D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin
VisualStudioInstallRootDirectory: 
MSBuildExtensionsPath:D:\User\cja\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin

[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        No solution files found in 'D:\my-proj\DMProg\app-server'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Resolved 'Microsoft.Build' to 'D:\User\Christian Jäckel\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Microsoft.Build.dll'
[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Loading project: D:\my-proj\DMProg\app-server\src\DMProg.Core\DMProg.Core.csproj
[dbug]: OmniSharp.MSBuild.ProjectFile.ProjectFileInfo
        'MSBuildExtensionsPath' set to 'D:\User\Christian Jäckel\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild'
[dbug]: OmniSharp.MSBuild.ProjectFile.ProjectFileInfo
        'CscToolPath' set to 'D:\User\Christian Jäckel\.vscode\extensions\ms-vscode.csharp-1.13.0\.omnisharp\msbuild\15.0\Bin\Roslyn'
[dbug]: OmniSharp.MSBuild.ProjectFile.ProjectFileInfo
        'CscToolExe' set to 'csc.exe'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.Build.resources, Version=15.1.0.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'Microsoft.Build.resources, Version=15.1.0.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a'
[warn]: OmniSharp.MSBuild.MSBuildProjectSystem
        Failed to load project file 'D:\my-proj\DMProg\app-server\src\DMProg.Core\DMProg.Core.csproj'.
D:\my-proj\DMProg\app-server\src\DMProg.Core\DMProg.Core.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk' specified could not be found.  D:\my-proj\DMProg\app-server\src\DMProg.Core\DMProg.Core.csproj
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List`1& projects, Boolean throwOnFileNotExistsError)
   at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(ILoggingService loggingService, BuildEventContext buildEventContext)
   at Microsoft.Build.Evaluation.Project.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.Project.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion)
   at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.LoadProject(String filePath, String solutionDirectory, ILogger logger, MSBuildInstance msbuildInstance, MSBuildOptions options, ICollection`1 diagnostics, ImmutableArray`1& targetFrameworks)
   at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Create(String filePath, String solutionDirectory, ILogger logger, MSBuildInstance msbuildInstance, MSBuildOptions options, ICollection`1 diagnostics)
   at OmniSharp.MSBuild.MSBuildProjectSystem.LoadProject(String projectFilePath)


Tracing enabled

--- Invoked hostfxr [commit hash: e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d] hostfxr_resolve_sdk

Probing path [D:\my-proj\DMProg\app-server\src\DMProg.Core\DMProg.Core.csproj\global.json] for global.json

Probing path [D:\my-proj\DMProg\app-server\src\DMProg.Core\global.json] for global.json

Probing path [D:\my-proj\DMProg\app-server\src\global.json] for global.json

Probing path [D:\my-proj\DMProg\app-server\global.json] for global.json

Found global.json [D:\my-proj\DMProg\app-server\global.json]

--- Resolving CLI version from global json [D:\my-proj\DMProg\app-server\global.json]

CLI version is [1.0.1] in global json file [D:\my-proj\DMProg\app-server\global.json]

Searching SDK directory in [C:\Program Files\dotnet]

CLI directory [C:\Program Files\dotnet\sdk\1.0.1] from global.json exists

Found CLI SDK in: C:\Program Files\dotnet\sdk\1.0.1

@anorborg
Copy link

anorborg commented Nov 9, 2017

I am also seeing this with the latest vs-code on macOS, omnishap, and dotnet on a fresh classlib project

Environment

ms-vscode.csharp 1.13.0

$ code --version
1.18.0
dcee2202709a4f223185514b9275aa4229841aa7

$ dotnet --info

.NET Command Line Tools (2.0.2)

Product Information:
 Version:            2.0.2
 Commit SHA-1 hash:  a04b4bf512

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.13
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.0.2/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

Error

Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk' specified could not be found. 

@DustinCampbell
Copy link
Member

@cjaeckel

When now loading the project the probing for the SDK path seems to happen after the actual project load.

I wish it were as simple as that, but I'm not sure. @nguerrera, do you know if this would even be possible?

@anorborg
Copy link

anorborg commented Nov 9, 2017

FYI, I manually installed 1.12.1 and it worked again

@DustinCampbell
Copy link
Member

@anorborg : As a workaround, you should also be able to make it work by setting the MSBuildSDKsPath environment variable to /usr/local/share/dotnet/sdk/2.0.2/Sdks.

@nguerrera
Copy link

When now loading the project the probing for the SDK path seems to happen after the actual project load.

I wish it were as simple as that, but I'm not sure. @nguerrera, do you know if this would even be possible?

From the looks of that log sequence, it seems like something evaluated the project without the resolver, then something else did it with the resolver. Are there two msbuilds involved somehow and one of them does not have the resolver?

@DustinCampbell
Copy link
Member

From the looks of that log sequence, it seems like something evaluated the project without the resolver, then something else did it with the resolver. Are there two msbuilds involved somehow and one of them does not have the resolver?

It does look that way, but OmniSharp does not run MSBuild in parallel and only one MSBuild is ever used. In the OmniSharp Log above, it is using the MSBuild that is included with OmniSharp, which includes it's own copy of the SdkResolvers.

@DustinCampbell
Copy link
Member

FWIW, this is starting to look like: dotnet/msbuild#2532.

@DustinCampbell
Copy link
Member

This is also happening here: #1846

@nguerrera
Copy link

CLI version is [1.0.1] in global json file [D:\my-proj\DMProg\app-server\global.json]
Found CLI SDK in: C:\Program Files\dotnet\sdk\1.0.1

Ah! CLI versions less than 1.0.4 had a bug where SDK to SDK imports did not use the right mechanism. This means they were fundametally broken when we introduced SDK resolution. The resolver will reject anything lower than 1.0.4.

We issue an error message for this case:

https://github.com/dotnet/cli/blob/f15495cee3d08c74403e45b3c3ef9e9a9897b670/src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs#L76-L79

But msbuild isn't surfacing it to the user. I thought this was due to the legacy Sdks directory, but here I see it happening without that present. https://github.com/dotnet/cli/issues/6887 tracks getting this error to surface correctly.

@DustinCampbell
Copy link
Member

Thanks @nguerrera! @cjaeckel : Have you considered updating your .NET Core SDK to a newer version? It sounds like that would address the problem: https://www.microsoft.com/net/download/windows. .NET Core SDK 1.0.4 is still available here, though a newer version might serve you better.

@DustinCampbell
Copy link
Member

I've just pushed a new release that should help address this issue: 1.13.1. We'll be pushing this to marketplace sometime today. However, if you want to try it out, you can follow the instructions here to install it.

@omartin2010
Copy link

Looks like even now, I needed to create launch code with the environment variable MSBuildSDKsPath set to the proper location c:\Program Files\dotnet\sdk\2.1.302\Sdks in my case. Is this normal at this point? Or did I improperly setup dotnet so it didn't alter my path?

@nguerrera
Copy link

@omartin2010 Is dotnet not on your PATH? How did you install it?

@omartin2010
Copy link

dotnet is on my path (specifically, c:\Program Files\dotnet\ is, but c:\Program Files\dotnet\sdk\2.1.302\SDKs wasn't. Is this expected?

@nguerrera
Copy link

Is this expected?

Yes, that is normal.

@omartin2010
Copy link

omartin2010 commented Oct 12, 2018 via email

@nguerrera
Copy link

I meant that it is expected that c:\Program Files\dotnet\ is on the PATH, but c:\Program Files\dotnet\sdk\2.1.302\SDKs is not.

do you know if it Iis expected that I need to manually add the dotnet core’s SDK subdirectory to the path to get this to work for a project that’s built using dotnet core that is in the path

This is not expected.

@nguerrera
Copy link

See also #2604 (comment)

@ChickJ
Copy link

ChickJ commented Oct 26, 2018

I would like to add my two cents to this:

  • I run OpenSUSE Tumbleweed
  • I've never installed Mono
  • A long time ago I used to manually download and install .NET Core
  • Everything worked fine
  • I transitioned to getting my packages from https://packages.microsoft.com/opensuse/42.2/prod
  • Everything worked fine
  • In Summer 2018 I transitioned to <TargetFramework>netcoreapp2.1</TargetFramework>
  • My work computer worked fine, my computer at home started having SDK resolution problems.
  • Updated work machine to
.NET Core SDK (reflecting any global.json):
 Version:   2.1.302
 Commit:    9048955601

Runtime Environment:
 OS Name:     opensuse-tumbleweed
 OS Version:  20181015
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/2.1.302/

Host (useful for support):
  Version: 2.1.2
  Commit:  811c3ce6c0

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

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  • Now both machines had SDK resolutions.

After picking through the GIT issues related to

'Microsoft.NET.Sdk' specified could not be found

To track down my problem I created a brand new project:

dotnet new console
COREHOST_TRACE=1 code .

This was enough to reproduce the problem and my log showed how Omnisharp resolved its paths.

...
MSBuildToolsDirectory32: ~/.vscode/extensions/ms-vscode.csharp-1.16.2/.omnisharp/1.32.7-beta.8/omnisharp/msbuild/15.0/Bin
MSBuildToolsDirectory64: ~/.vscode/extensions/ms-vscode.csharp-1.16.2/.omnisharp/1.32.7-beta.8/omnisharp/msbuild/15.0/Bin
MSBuildSDKsPath: ~/.vscode/extensions/ms-vscode.csharp-1.16.2/.omnisharp/1.32.7-beta.8/omnisharp/msbuild/15.0/Bin/Sdks
CurrentMSBuildConfigurationFile: ~/.vscode/extensions/ms-vscode.csharp-1.16.2/.omnisharp/1.32.7-beta.8/omnisharp/msbuild/15.0/Bin/MSBuild.dll.config
CurrentMSBuildExePath: ~/.vscode/extensions/ms-vscode.csharp-1.16.2/.omnisharp/1.32.7-beta.8/omnisharp/msbuild/15.0/Bin/MSBuild.dll
CurrentMSBuildToolsDirectory: ~/.vscode/extensions/ms-vscode.csharp-1.16.2/.omnisharp/1.32.7-beta.8/omnisharp/msbuild/15.0/Bin
VisualStudioInstallRootDirectory: 
MSBuildExtensionsPath: ~/.vscode/extensions/ms-vscode.csharp-1.16.2/.omnisharp/1.32.7-beta.8/omnisharp/msbuild/15.0/Bin
...

Of course there is no Microsoft.NET.Sdk in the built in $(MSBuildSDKsPath) hence my error.

The SDK 'Microsoft.NET.Sdk' specified could not be found.  ~/Work/se.client/se.client.csproj`

Somehow I need to get Omnisharp to resolve to /usr/share/dotnet/sdk instead. My problem was a combination of a dead soft link and my PATH variable.

@host:~/Work/se.client$ echo $PATH
~/bin:/usr/local/bin:/usr/bin:/bin:/~/.dotnet/tools

@host:~/Work/se.client$ which dotnet
/usr/bin/dotnet

@host:~/Work/se.client$ ls
lrwxrwxrwx 1 root root 18 Oct 26 07:56 dotnet -> /opt/dotnet/dotnet

The link /usr/local/bin/dotnet was invalid; it is a remnant of my old manual installation, i.e. /opt/dotnet no longer exists. Deleting the dead link fixed my problem and everything works again.

I surmise the following:

  • Omnisharp uses its own implementation to search PATH
  • It does not validate links
  • It errors out trying to run an invalid dotnet and falls back to a different
    resolution.

To recreate my error on a working system:

mkdir -p ~/snf/bin
cd ~/snf/bin
ln -sf `which dotnet`_bad dotnet
mkdir -p ~/snf/test
cd ~/snf/test
dotnet new console
export PATH=~/snf/bin:${PATH}
COREHOST_TRACE=1 code .

@rchande
Copy link

rchande commented Oct 29, 2018

@ChickJ Thanks for sharing--you're right that we could improve how we handle unresolvable paths. I've filed #2629 to track this.

@igoichuk
Copy link

igoichuk commented Feb 2, 2019

I've got the same issue: 'Microsoft.NET.Sdk' specified could not be found. Macosx, OmniSharp 1.18.0-beta6.
Fixed it by setting up MSBuildSDKsPath=/usr/local/share/dotnet/sdk/3.0.100-preview-010184/Sdks
I assume it is not expected behaviour.

dotnet --info
`.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview-010184
Commit: c57bde4593

Runtime Environment:
OS Name: Mac OS X
OS Version: 10.13
OS Platform: Darwin
RID: osx.10.13-x64
Base Path: /usr/local/share/dotnet/sdk/3.0.100-preview-010184/

Host (useful for support):
Version: 3.0.0-preview-27324-5
Commit: 63a01b08e5

.NET Core SDKs installed:
2.2.103 [/usr/local/share/dotnet/sdk]
3.0.100-preview-010184 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview-19075-0444 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview-27324-5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
`

@mickaelistria
Copy link

This issue doesn't seem specific to VSCode integration and can happen woth OmniSharp roslyn in general.
See OmniSharp/omnisharp-roslyn#1416 (comment)

@b01
Copy link

b01 commented May 11, 2019

So I ran into this issue today as well. But I fixed it.

I'm running:

  • Windows 10 v1803
  • .NET Core v2.2
  • VSCode v1.33.1

I think what caused it was my process:

  1. Installed .Net core (no previous version of .NET was installed and I did not restart laptop).
  2. Next do the Tutorial https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code.
  3. Get an error:
    Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk' specified could not be found. C:\Path\to\your\project\file\here.csproj

To possibly resolve:

  1. Restart computer.
  2. Open Visual Studio Code and reload/re-install the extension.

Could it really be possible that a simple restart after installing core and before installing the extension to allow environment variables to exist/update is the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants