omnisharp-roslyn: OmniSharp.MSBuild.Discovery.MSBuildLocator picks wrong MSBuild path
From @pquiring on December 25, 2017 17:27
Environment data
dotnet --info output:
.NET Command Line Tools (2.1.3)
Product Information: Version: 2.1.3 Commit SHA-1 hash: a0ca411ca5
Runtime Environment: OS Name: Windows OS Version: 10.0.16299 OS Platform: Windows RID: win10-x64 Base Path: C:\Apps\dotnet\sdk\2.1.3\
Microsoft .NET Core Shared Framework Host
Version : 2.0.4 Build : 7f262f453d8c8479b9af91d34c013b3aa05bc1ff
VS Code version: 1.19.1
C# Extension version: 1.13.1
Steps to reproduce
Install .Net Core standalone Install VS Code Install VS Build Tools with VC++ only (not .NET component) or Install VS IDE with VC++ only (not .NET component) Open .csproj in VS Code.
Expected behavior
OmniSharp runs
Actual behavior
OmniSharp tries to use MSBuild from VC++ and fails.
Starting OmniSharp server at 12/25/2017, 12:02:45 PM
Target: c:\files\workspace\qt\apps\passwords
OmniSharp server started
Path: C:\Users\User\.vscode\extensions\ms-vscode.csharp-1.14.0-beta2\.omnisharp\OmniSharp.exe
PID: 9980
[info]: OmniSharp.Stdio.Host
Starting OmniSharp on Windows 6.2.9200.0 (x64)
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 2 MSBuild instance(s)
1: Visual Studio Build Tools 2017 15.5.27130.2010 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
2: StandAlone 15.0 - "C:\Users\User\.vscode\extensions\ms-vscode.csharp-1.14.0-beta2\.omnisharp\msbuild\15.0\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: Visual Studio Build Tools 2017 15.5.27130.2010 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
[info]: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in 'c:\files\workspace\qt\apps\passwords'.
[info]: OmniSharp.Cake.CakeProjectSystem
Could not find any Cake files
[info]: OmniSharp.DotNet.DotNetProjectSystem
Initializing in c:\files\workspace\qt\apps\passwords
[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.ProjectSystem
No solution files found in 'c:\files\workspace\qt\apps\passwords'
[info]: OmniSharp.MSBuild.ProjectManager
Queue project update for 'c:\files\workspace\qt\apps\passwords\passwords.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in 'c:\files\workspace\qt\apps\passwords'.
[info]: OmniSharp.Script.ScriptProjectSystem
Could not find any CSX files
[info]: OmniSharp.Stdio.Host
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.Stdio.Host
Configuration finished.
[info]: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location 'c:\files\workspace\qt\apps\passwords' on host 1332.
[info]: OmniSharp.MSBuild.ProjectManager
Loading project: c:\files\workspace\qt\apps\passwords\passwords.csproj
[fail]: OmniSharp.MSBuild.ProjectLoader
The "GetReferenceNearestTargetFrameworkTask" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin" directory.
[warn]: OmniSharp.MSBuild.ProjectManager
Failed to load project file 'c:\files\workspace\qt\apps\passwords\passwords.csproj'.
c:\files\workspace\qt\apps\passwords\passwords.csproj
If I install .NET in VS Build Tools it works.
How can I force OmniSharp to ignore MSbuild environments that do NOT have .NET included?
Thanks.
Copied from original issue: OmniSharp/omnisharp-vscode#1941
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 12
- Comments: 62 (13 by maintainers)
Work around: Rename “C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild” to MSBuild.disabled or Rename “C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild” to MSBuild.disabled
@UncleInf @johnnyreilly @boris-741 @LuizPelegrini @zvinless I’m sorry you’re running into issues. From what’s reported, it sounds like there’s an issue with the “standalone” MSBuild shipped with OmniSharp on Windows. There are a couple of workarounds you can do while we investigate:
Thanks for your patience–we are actively investigating.
I ran into this problem in a .NET Core project, the initial symptoms were many compile errors that boiled down to
You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. It turned out that instead of the built-in MSBuild, OmniSharp was selecting the one from VS2017.With VS 2017
OmniSharp log:
Result:
Error reported in VS Code:
The type 'ValueType' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. (CS0012)(and 400+ other errors) Compilation: works as expected. Seems like the build task uses the extension’s MSBuild, but OmniSharp uses the VS2017 one.After installing VS 2019
OmniSharp log:
Result:
It works.
Adding
$USERPROFILE\.omnisharp\omnisharp.jsonwith specific MSBuildSdksPath as mentioned in https://github.com/OmniSharp/omnisharp-vscode/issues/1727 had no effect – the VS2019 one still got selected. Adding omnisharp.json in the project directory also didn’t have an effect.I was a curious about this and tried to dig a bit to find out why this happens or what other options are there to control the choice of MSBuild to be used. Seems like it’s on purpose that the builtin MSBuild is sorted lower than VS ones (source), which for me seems strange since the current builtin one is MSBuild 16, while VS2017 is MSBuild 15.
Upon seeing this method I see now that it’s also not a coincidence that VS 2019 / MSBuild 16 was picked over MSBuild 15; seems like the “pick 16 over 15” rule wouldn’t apply to the builtin MSBuild, though, since it gets a lower score. That is very unfortunate, seems like there is a dependency on MSBuild 16 but MSBuild 15 can be picked if you happen not to have a newer VS, which in my case caused some lost time in debugging all of this.
I’ve had this problem in OSX. Went to user settings in VS Code and disabled “Global Mono”. It loads the
StandAlone 15.0now.Same problem in vscode today after omnisharp update
👍 would like a real workaround. I just uninstalled the MS Build Tools for now.
after struggling for couple of days finally this solution worked out for me. Thank you
unfortunately the embedded msbuild is not functionally equivalent to that what ships with mono or VS itself, this is particularly relevant for example for unity projects or projects with custom SDK, and should normally be the last resort fallback.
just like we eliminated VS2017 from being discovered though, I can imagine we will soon eliminate VS2019 <16.3 too which will make this issue go away.
That said, I don’t think it’s a terrible assumption that if you have VS2019 installed and want to do .NET Core 3.1 on your machine, your VS2019 will be updated accordingly.
related: https://github.com/OmniSharp/omnisharp-roslyn/pull/1545
Date is now almost 2020 and we still are facing same issue.for sake of god tell us how to specify msbuild path manually.
MSBuildSdksPathis not working for me either.I have the same problem. Here’s the output of the build locator:
I’ve got .NET Core 3.0 SDK installed as well as multiple 2.x versions and VS 2019. The VS 2019 MSBuild probably gets the priority and as a result, I’m getting the following error:
Update: Upgrading VS to the latest (16.3.x) version fixes the issue.
I’m having the same issue:
dotnet --info
Startup log:
What is the recommended work around?
Having the same issue, hiding the VS MSBuild works but I’m getting alarming errors in omni logs. And I’m getting wrong c# version errors on c# 8 syntax. I tried
<LangVersion>8.0</LangVersion>and<LangVersion>latest</LangVersion>, doesn’t seem to help. omnisharp.logEdit: Once I installed VS 2019 Preview, omni picked up that MSBuild (16) and now everything works dandy. For now that’s the msbuild to use, and I think it’s only publicly available with 2019 preview, unless you have a sneaky insiders 2019 build tools install.
Another data point… I just upgraded dotnet using chocolatey (was 2.1.101 or something, now 2.1.403). Then created a new project:
Which results in this OUTPUT:
My
dotnet --infooutput is:My guess is that it has something to do with this:
Which I would imagine might have
dotnetmentioned (as indotnet msbuild). Mydotnetinstall is at:I just tried upgrading to the 1.17.0 (prerelease) just to see if it changed anything… It didn’t still having this issue.
Also tried global settings:
But had the same outcome.
Well, my final solution is to remove Microsoft build tools altogether leaving only the dotnetcore-sdk. Not sure why my build tools didn’t work but i don’t need em anyway…
FYI, instructions for installing releases of C# for VS Code are here: https://github.com/OmniSharp/omnisharp-vscode/wiki/Installing-Beta-Releases.
Downgrading omnisharp to 1.15 and disabling extension auto update worked for me! Thanks for the support @rchande !
This started happening for me after the 1.16.0 update, too: