vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

"'Microsoft.NET.Sdk' could not be found" when running VS Code from Git Bash

Open inosik opened this issue 9 years ago • 16 comments

Environment data

dotnet --info output:

.NET Command Line Tools (2.0.0)

Product Information:
 Version:            2.0.0
 Commit SHA-1 hash:  cdcd1928c9

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x64
 Base Path:   C:\Users\nosikil\scoop\apps\dotnet-sdk\current\sdk\2.0.0\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

VS Code version: 1.15.0 C# Extension version: 1.12.1

Steps to reproduce

In Git Bash:

dotnet new console
code.cmd .

Note that Git, the .NET SDK and VS Code are installed with Scoop on my machine.

Expected behavior

This is what I get when running VS Code from the console or PowerShell:

Starting OmniSharp server at 14.9.2017, 15:09:52
    Target: d:\temp

OmniSharp server started
    Path: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\OmniSharp.exe
    PID: 5580

OmniSharp: -s d:\temp --hostPID 4480 --stdio DotNet:enablePackageRestore=false --encoding utf-8 --loglevel information formattingOptions:useTabs=false formattingOptions:tabSize=4 formattingOptions:indentationSize=4
[info]: OmniSharp.Startup
        Omnisharp server running using Stdio at location 'd:\temp' on host 4480.
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Initializing in d:\temp
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Auto package restore: False
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Update workspace context
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Resolving projects references
[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Omnisharp will use local MSBuild.
    MSBUILD_EXE_PATH: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\msbuild\MSBuild.exe
    MSBuildExtensionsPath: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\msbuild

[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        No solution files found in 'd:\temp'
[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Loading project: d:\temp\temp.csproj

[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Update project: temp
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in 'd:\temp'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.Services.WorkspaceHelper
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.Startup
        Configuration finished.

Actual behavior

This is what I get with Git Bash:

Starting OmniSharp server at 14.9.2017, 15:06:24
    Target: d:\temp

OmniSharp server started
    Path: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\OmniSharp.exe
    PID: 12952

OmniSharp: -s d:\temp --hostPID 7308 --stdio DotNet:enablePackageRestore=false --encoding utf-8 --loglevel information formattingOptions:useTabs=false formattingOptions:tabSize=4 formattingOptions:indentationSize=4
[info]: OmniSharp.Startup
        Omnisharp server running using Stdio at location 'd:\temp' on host 7308.
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Initializing in d:\temp
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Auto package restore: False
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Update workspace context
[info]: OmniSharp.DotNet.DotNetProjectSystem
        Resolving projects references
[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Omnisharp will use local MSBuild.
    MSBUILD_EXE_PATH: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\msbuild\MSBuild.exe
    MSBuildExtensionsPath: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\msbuild

[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        No solution files found in 'd:\temp'
[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Loading project: d:\temp\temp.csproj
[warn]: OmniSharp.MSBuild.MSBuildProjectSystem
        Failed to load project file 'd:\temp\temp.csproj'.
d:\temp\temp.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk' specified could not be found.  d:\temp\temp.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, String sdksPath, ILogger logger, MSBuildOptions options, ICollection`1 diagnostics, ImmutableArray`1& targetFrameworks)
   at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Create(String filePath, String solutionDirectory, String sdksPath, ILogger logger, MSBuildOptions options, ICollection`1 diagnostics)
   at OmniSharp.MSBuild.MSBuildProjectSystem.LoadProject(String projectFilePath)

[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in 'd:\temp'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.Services.WorkspaceHelper
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.Startup
        Configuration finished.

inosik avatar Sep 14 '17 13:09 inosik

After launching VS Code from Git Bash, could you try running dotnet --info from within VS Code's Integrated Terminal and pasting the output here?

DustinCampbell avatar Sep 14 '17 16:09 DustinCampbell

It's the same as above:

.NET Command Line Tools (2.0.0)

Product Information:
 Version:            2.0.0
 Commit SHA-1 hash:  cdcd1928c9

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x64
 Base Path:   C:\Users\nosikil\scoop\apps\dotnet-sdk\current\sdk\2.0.0\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

inosik avatar Sep 15 '17 06:09 inosik

Thanks! I'll get WSL set up on my machine and take a look.

DustinCampbell avatar Sep 15 '17 13:09 DustinCampbell

This has nothing to do with WSL, just plain Windows + Bash which comes with Git.

Can I make the output more verbose, to see what parameters MSBuild gets?

inosik avatar Sep 15 '17 17:09 inosik

Thanks! I was thinking this would be related to another issue I was talking to somebody about with WSL. Glad I'm wrong. :smile:

Try setting the "omnisharp.loggingLevel": "debug" option in VS Code's preferences. That might provide a few clues in the log.

DustinCampbell avatar Sep 15 '17 17:09 DustinCampbell

Thanks, I'll try that on Monday.

inosik avatar Sep 15 '17 17:09 inosik

The MSBuild parameters are the same for both cases:

[dbug]: OmniSharp.MSBuild.MSBuildProjectSystem
        MSBuild environment:
Mode: Standalone
RunningTests: False
RunningInVisualStudio: False
MSBuildToolsDirectory32: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\msbuild
MSBuildToolsDirectory64: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\msbuild
MSBuildSDKsPath: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\msbuild\Sdks
CurrentMSBuildConfigurationFile: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\msbuild\MSBuild.exe.config
CurrentMSBuildExePath: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\msbuild\MSBuild.exe
CurrentMSBuildToolsDirectory: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\msbuild
VisualStudioInstallRootDirectory:
MSBuildExtensionsPath: C:\Users\nosikil\.vscode\extensions\ms-vscode.csharp-1.12.1\.omnisharp\msbuild

The only difference I see before I get the warning message with the exception is this:

[dbug]: OmniSharp.MSBuild.ProjectFile.ProjectFileInfo
        Using MSBuildSDKsPath: C:\Users\nosikil\scoop\apps\dotnet-sdk\current\sdk\2.0.0\Sdks

This message is not logged when I run VS Code from Bash.

To me this looks like MSBuild searches for the SDKs in some default directory, probably somewhere in .vscode\ms-vscode.csharp-1.12.1\.omnisharp\, when I run VS Code from Bash. I guess I need a debug build of OmniSharp.

inosik avatar Sep 18 '17 06:09 inosik

The message should be logged when this call adds something to the globalProperties dictionary.

inosik avatar Sep 18 '17 06:09 inosik

I think I tracked it down. This is very similar to dotnet/cli#3995 and dotnet/corefx#13146.

When I'm in Bash, I have the home and HOME environment variables. I think this breaks the interaction between OmniSharp and dotnet --info, which then probably returns some default infos. When I do unset home before running VS Code, everything works as expected. You can reproduce it when you do foo=1 FOO=1 code . in Bash.

inosik avatar Sep 18 '17 09:09 inosik

Thanks for the lead! At the very least, I'll add some logging around this to see if we can make it clearer when this fails. It's a little tricky because it's not exactly an error case when the .NET Core SDK doesn't work. After all, we support .NET Framework, Unity and Xamarin projects. However, it should be easier to trace the issue.

DustinCampbell avatar Sep 18 '17 16:09 DustinCampbell

I have the same issue on my macOS and I have no idea how to track the bug in omnisharp. I guess I'll have to dig into the codebase to see where it's taking its path from because it's clearly not using the one where donet actually lives.

bandrei avatar Jul 10 '18 07:07 bandrei

Ok, it looks like I managed to solve it by running dotnet restore on the project whcih fixed the omnisharp server which is now starting. After this I deleted a .env file and re-started VSCode to update it, after which things started working.

bandrei avatar Jul 10 '18 08:07 bandrei

I have the same issue on macOS when opening a folder directly in VS Code. Opening VS Code from Applications, then opening the folder, makes the problem disappear.

hjerpbakk avatar Sep 10 '18 06:09 hjerpbakk

i have the same issue on my linux:

https://github.com/OmniSharp/omnisharp-vscode/issues/2803

kentahikaru avatar Jan 23 '19 18:01 kentahikaru

i installed .NET Core SDKs: 2.2.104 AND 3.0.100-preview-010184. (ubuntu 18) and had same problem. but after creating global.json in my project folder and defining 2.2.104 as my sdk, this problem solved.

guftall avatar Apr 16 '19 05:04 guftall

Closing as a duplicate of #3541 which will track these issues

cartermp avatar Mar 26 '20 21:03 cartermp