OmniSharp is selecting the wrong MSBuild location when opening .NET Core 2 applications. The logs tell the story:
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 3 MSBuild instance(s)
1: Visual Studio Build Tools 2019 16.0.28803.452 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
2: Visual Studio Professional 2017 15.8.28010.2041 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
3: StandAlone 15.0 - "C:\Users\x\.vscode\extensions\ms-vscode.csharp-1.19.1\.omnisharp\1.32.19\.msbuild\Current\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: Visual Studio Professional 2017 15.8.28010.2041 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
Here we see that even though MSBuild 16 is detected via VS Build Tools 2019, it chooses MSBuild 15. Then:
[fail]: OmniSharp.MSBuild.ProjectLoader
Project X is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Project X supports: netcoreapp2.2 (.NETCoreApp,Version=v2.2)
[fail]: OmniSharp.MSBuild.ProjectLoader
Version 2.2.204 of the .NET Core SDK requires at least version 16.0.0 of MSBuild. The current available version of MSBuild is 15.8.169.51996. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
[fail]: OmniSharp.MSBuild.ProjectLoader
The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
We see that Omnisharp is complaining about not having version 16 of MSBuild available. But as we saw above, it's right there 馃槶. Weirdly, it suggests downgrading the SDK rather than fixing MSBuild. This seems exactly backwards for the majority case.
I tried creating an omnisharp.json like this:
{
"MsBuild": {
"MSBuildSdksPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\MSBuild\\Current\\Bin"
}
}
But it had no effect. I also tried pointing it to the dotnet sdk folder. That didn't do anything, either.
Project is loaded successfully. _Visual Studio installs don't mess with OmniSharp._
Project is not loaded. OmniSharp behavior is coupled to installs of VS.
I hit this issue in the middle of a project upgrade from DotNetCore 1.0 to 2.0, so there is a fair amount of noise here about broken projects.
Starting OmniSharp server at 5/18/2019, 12:26:01 PM
Target: c:\Source\Project\Project.sln
OmniSharp server started.
Path: C:\Users\user.vscodeextensions\ms-vscode.csharp-1.19.1.omnisharp\1.32.19\OmniSharp.exe
PID: 3860
Starting OmniSharp on Windows 6.2.9200.0 (x64)
DotNetPath set to dotnet
Located 3 MSBuild instance(s)
1: Visual Studio Build Tools 2019 16.0.28803.452 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
2: Visual Studio Professional 2017 15.8.28010.2041 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
3: StandAlone 15.0 - "C:\Users\user\.vscode\extensions\ms-vscode.csharp-1.19.1\.omnisharp\1.32.19\.msbuild\Current\Bin"
Registered MSBuild instance: Visual Studio Professional 2017 15.8.28010.2041 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"
Detecting Cake files in 'c:\Source\Project'.
Could not find any Cake files
Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
Detecting projects in 'c:\Source\Project\Project.sln'.
Queue project update for 'c:\Source\Project\src\Project.Generation\Project.Generation.csproj'
Queue project update for 'c:\Source\Project\src\Project.Server\Project.Server.csproj'
Queue project update for 'c:\Source\Project\test\Project.Server.IntegrationTests\Project.Server.IntegrationTests.csproj'
Queue project update for 'c:\Source\Project\test\Project.Server.Tests\Project.Server.Tests.csproj'
Detecting CSX files in 'c:\Source\Project'.
Could not find any CSX files
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
Loading project: c:\Source\Project\src\Project.Generation\Project.Generation.csproj
Configuration finished.
Omnisharp server running using Stdio at location 'c:\Source\Project' on host 16876.
Project Project.Server is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Project Project.Server supports: netcoreapp2.2 (.NETCoreApp,Version=v2.2)
Version 2.2.204 of the .NET Core SDK requires at least version 16.0.0 of MSBuild. The current available version of MSBuild is 15.8.169.51996. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Failed to load project file 'c:\Source\Project\src\Project.Generation\Project.Generation.csproj'.
c:\Source\Project\src\Project.Generation\Project.Generation.csproj
C:\Source\Project\src\Project.Generation\Project.Generation.csproj(0,0): Error: Project Project.Server is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Project Project.Server supports: netcoreapp2.2 (.NETCoreApp,Version=v2.2)
c:\Source\Project\src\Project.Server\Project.Server.csproj(0,0): Error: Version 2.2.204 of the .NET Core SDK requires at least version 16.0.0 of MSBuild. The current available version of MSBuild is 15.8.169.51996. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
c:\Source\Project\src\Project.Server\Project.Server.csproj(0,0): Error: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Loading project: c:\Source\Project\src\Project.Server\Project.Server.csproj
Failed to load project file 'c:\Source\Project\src\Project.Server\Project.Server.csproj'.
c:\Source\Project\src\Project.Server\Project.Server.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found. c:\Source\Project\src\Project.Server\Project.Server.csproj
at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
at Microsoft.Build.Evaluation.Evaluator4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List1& projects, SdkResult& sdkResult, Boolean throwOnFileNotExistsError)
at Microsoft.Build.Evaluation.Evaluator4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult)
at Microsoft.Build.Evaluation.Evaluator4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
at Microsoft.Build.Evaluation.Evaluator4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
at Microsoft.Build.Evaluation.Evaluator4.Evaluate(ILoggingService loggingService, BuildEventContext buildEventContext)
at Microsoft.Build.Evaluation.Project.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
at Microsoft.Build.Evaluation.Project.Initialize(IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary2 globalProperties, String toolsVersion)
at OmniSharp.MSBuild.ProjectLoader.EvaluateProjectFileCore(String filePath) in C:\projects\omnisharp-roslyn\src\OmniSharp.MSBuild\ProjectLoader.cs:line 129
at OmniSharp.MSBuild.ProjectLoader.BuildProject(String filePath) in C:\projects\omnisharp-roslyn\src\OmniSharp.MSBuild\ProjectLoader.cs:line 72
at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Load(String filePath, ProjectIdInfo projectIdInfo, ProjectLoader loader) in C:\projects\omnisharp-roslyn\src\OmniSharp.MSBuild\ProjectFile\ProjectFileInfo.cs:line 94
at OmniSharp.MSBuild.ProjectManager.<>c__DisplayClass30_0.<LoadProject>b__0() in C:\projects\omnisharp-roslyn\src\OmniSharp.MSBuild\ProjectManager.cs:line 293
at OmniSharp.MSBuild.ProjectManager.LoadOrReloadProject(String projectFilePath, Func1 loader) in C:\projects\omnisharp-roslyn\src\OmniSharp.MSBuild\ProjectManager.cs:line 304
Loading project: c:\Source\Project\test\Project.Server.IntegrationTests\Project.Server.IntegrationTests.csproj
Project Project.Server is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Project Project.Server supports: netcoreapp2.2 (.NETCoreApp,Version=v2.2)
Version 2.2.204 of the .NET Core SDK requires at least version 16.0.0 of MSBuild. The current available version of MSBuild is 15.8.169.51996. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Failed to load project file 'c:\Source\Project\test\Project.Server.IntegrationTests\Project.Server.IntegrationTests.csproj'.
c:\Source\Project\test\Project.Server.IntegrationTests\Project.Server.IntegrationTests.csproj
C:\Source\Project\test\Project.Server.IntegrationTests\Project.Server.IntegrationTests.csproj(0,0): Error: Project Project.Server is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Project Project.Server supports: netcoreapp2.2 (.NETCoreApp,Version=v2.2)
c:\Source\Project\src\Project.Server\Project.Server.csproj(0,0): Error: Version 2.2.204 of the .NET Core SDK requires at least version 16.0.0 of MSBuild. The current available version of MSBuild is 15.8.169.51996. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
c:\Source\Project\src\Project.Server\Project.Server.csproj(0,0): Error: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Loading project: c:\Source\Project\test\Project.Server.Tests\Project.Server.Tests.csproj
Project Project.Server is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Project Project.Server supports: netcoreapp2.2 (.NETCoreApp,Version=v2.2)
Version 2.2.204 of the .NET Core SDK requires at least version 16.0.0 of MSBuild. The current available version of MSBuild is 15.8.169.51996. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Failed to load project file 'c:\Source\Project\test\Project.Server.Tests\Project.Server.Tests.csproj'.
c:\Source\Project\test\Project.Server.Tests\Project.Server.Tests.csproj
C:\Source\Project\test\Project.Server.Tests\Project.Server.Tests.csproj(0,0): Error: Project Project.Server is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Project Project.Server supports: netcoreapp2.2 (.NETCoreApp,Version=v2.2)
c:\Source\Project\src\Project.Server\Project.Server.csproj(0,0): Error: Version 2.2.204 of the .NET Core SDK requires at least version 16.0.0 of MSBuild. The current available version of MSBuild is 15.8.169.51996. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
c:\Source\Project\src\Project.Server\Project.Server.csproj(0,0): Error: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Attempted to update project that is not loaded: c:\Source\Project\src\Project.Generation\Project.Generation.csproj
Attempted to update project that is not loaded: c:\Source\Project\src\Project.Server\Project.Server.csproj
Attempted to update project that is not loaded: c:\Source\Project\test\Project.Server.IntegrationTests\Project.Server.IntegrationTests.csproj
Attempted to update project that is not loaded: c:\Source\Project\test\Project.Server.Tests\Project.Server.Tests.csproj
Empty
VSCode version: 1.34.0
C# Extension: 1.19.1
Dotnet Information
.NET Core SDK (reflecting any global.json):
Version: 2.2.204
Commit: 8757db13ec
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.204\
Host (useful for support):
Version: 2.2.5
Commit: 0a3c9209c0
.NET Core SDKs installed:
1.1.0 [C:\Program Files\dotnet\sdk]
2.2.204 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
Hi,
I'm facing the same issue.
I don't know all the effects this issue is causing in vs-code. I can't use "Go To Definition" command and sometimes intellisense simply doesn't work as expected.
`Starting OmniSharp server at 10/15/2019, 9:55:57 AM
Target: c:dev\WebApp1
OmniSharp server started.
Path: c:\Users\Username.vscodeextensions\ms-vscode.csharp-1.21.4.omnisharp\1.34.4\OmniSharp.exe
PID: 4892
Starting OmniSharp on Windows 6.2.9200.0 (x64)
DotNetPath set to dotnet
_[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 2 MSBuild instance(s)
1: Visual Studio Community 2019 16.3.29409.12 - "C:\Program Files (x86)\Microsoft Visual Studio2019\Community\MSBuild\Current\Bin"
2: StandAlone 16.0 - "C:\Users\Username.vscodeextensions\ms-vscode.csharp-1.21.4.omnisharp\1.34.4.msbuild\Current\Bin"
Registered MSBuild instance: Visual Studio Community 2019 16.3.29409.12 - "C:\Program Files (x86)\Microsoft Visual Studio2019\Community\MSBuild\Current\Bin"_
Detecting Cake files in 'c:dev\WebApp1'.
Could not find any Cake files
No solution files found in 'c:dev\WebApp1'
Queue project update for 'c:dev\WebApp1\WebApp1.csproj'
Detecting CSX files in 'c:dev\WebApp1'.
Could not find any CSX files
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
Loading project: c:dev\WebApp1\WebApp1.csproj
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.EditorConfigWorkspaceOptionsProvider, Order: 200
Configuration finished.
Omnisharp server running using Stdio at location 'c:dev\WebApp1' on host 17620.
Successfully loaded project file 'c:dev\WebApp1\WebApp1.csproj'.
Adding project 'c:dev\WebApp1\WebApp1.csproj'
Update project: WebApp1`
in fact I will close this issue because this has been resolved - OmniSharp now ships with 16.3 MSBuild and supports .NET Core 3.0 too.
@franlyreynoso it uses the correct one - VS 2019 version of msbuild is preferred over the stand alone one. "go to definition" issue is not a related thing - it's a regression in 1.21.4, see https://github.com/OmniSharp/omnisharp-vscode/issues/3344#issuecomment-541553080 for a workaround
in fact I will close this issue because this has been resolved - OmniSharp now ships with 16.3 MSBuild and supports .NET Core 3.0 too.
@franlyreynoso it uses the correct one - VS 2019 version of msbuild is preferred over the stand alone one. "go to definition" issue is not a related thing - it's a regression in 1.21.4, see #3344 (comment) for a workaround
Thanks! That fixed it.