Open fogzot opened 6 years ago
@fogzot Do non-Razor projects work (eg dotnet new console
)?
I had a similar issue, but solved it. Try adding this to your PATH
variable (.bashrc, .zshrc...):
MSBuildSDKsPath=/path/to/dotnet/sdk
# export MSBuildSDKsPath=/opt/dotnet/sdk/2.1.403/Sdks
# export PATH=$MSBuildSDKsPath:$PATH
I'm on Arch, so you'll probably need to modify the path.
@anticide 's method worked for me.
MSBuildSDKsPath="/usr/share/dotnet/sdk/2.1.403/Sdks/"
on Ubuntu
Though before I changed it, I noticed the path to Mono Sdks (instead of DotNet Sdks) was being used by Omnisharp.
As you can see in the exception's message, The following path was used : "/usr/lib/mono/msbuild/15.0/bin/Sdks/Microsoft.NET.Sdk.Web/Sdk/Sdk.props"
I don't know how omnisharp works in depth, But I think the problem is that Omnisharp (or maybe even msbuild, not sure) either doesn't know whether to use Mono or dotnet for a project, Or maybe it's just some Path variable conflict.
Note : I haven't tried it, But I think another workaround is to remove your Mono Sdks :grin: Though that's not a wise choice if you're gonna need it.
i had this problem on ubuntu 18.04, when i installed mono-complete and mono-develop after installing dotnet core. When i removed mono, and reinstall apt-transport-https from dotnet, the problem disappeared
@fogzot Do non-Razor projects work (eg
dotnet new console
)?
Yes. If the project doesn't contain a reference to the Web SDK (not explicitly the Razor one, just Web) everything works.
I can confirm that setting MSBuildSDKsPath
to the .NET Core sdks directory fixes the issue.
A better solution would be:
export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
This way you don't have to update SDK's version.
Has there ever been an explanation of this? I see this error pop up fairly regularly around msbuild sdk resolution. Here is a similar issue logged over there: https://github.com/Microsoft/msbuild/issues/2532. Should setting MSBuildSDKsPath
be required? Is there a corruption of some installation of the tooling?
The problem is, that msbuild is also used by mono IDEs like MonoDevelop, So the previous path which is set to Mono SDKs (instead of dotnet SDKs) may be required by an IDE that compiles Mono code. I haven't tried, But setting MSBuildSDKsPath may indeed conflict with mono IDEs.
I'll check to see if it happens and update this comment asap. If it does, Perhaps a better way is to add the following in VS Code's launch script :
For Ubuntu users :
export MSBuildSDKsPath=/usr/share/dotnet/sdk/$(dotnet --version)/Sdks/
For Arch users :
export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
UPDATE : I tested a simple console project using MonoDevelop 7 (FlatPack version though), and there was no problem. Since the issue is closed and continued on other places I'll be watching them now.
There are a few things at play here. Let me give some background on how this is supposed to work. When MSBuild encounters <Project Sdk=...>
, <Import Sdk=...>
or <Sdk ...>
, it calls into its SdkResolvers. These are plugins that live alongside MSBuild. One in particular, Microsoft.DotNet.MSBuildSdkResolver, resolves Sdks from the .NET Core SDK location based on dotnet
being on PATH. There is also a default resolver that looks in MSBuildSdksPath. The default resolver is used if the plugin resolvers are not present or fail to find the Sdk in question. (* Technically, there is a priority given to each resolver and default resolver can go in between plugins, but the priorities aren't assigned that way in practice.)
This error indicates that the default resolver was used to locate the Web SDK (because its Sdk.props is not in a .NET Core SDK location, but rather in the default MSBuildSdksPath), but then it failed to find the Razor SDK in the same default location:
Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk.Razor' specified could not be found. /usr/lib/mono/msbuild/15.0/bin/Sdks/Microsoft.NET.Sdk.Web/Sdk/Sdk.props
So the first issue I see is that this mono msbuild is bundling Microsoft.NET.Sdk.Web without its Microsoft.NET.Sdk.Razor dependency. This means that the default sdk resolver will never be able to load web projects. Mono msbuild should bundle Microsoft.NET.Sdk.Razor if it is going to bundle Microsoft.NET.Sdk.Web in its default MSBuildSdksPath.
This default resolver would only be used if Microsoft.DotNet.MSBuildSdkResolver failed, which would happen in some normal circumstances:
dotnet
is not on the PATHFrom other hints above, these do not seem to apply here, but those are still the first things to check.
The next thing to verify is that the mono msbuild being used has Microsoft.DotNet.MSBuildSdkResolver in . /usr/lib/mono/msbuild/15.0/bin/SdkResolvers.
Finally, if it does, then there may be a bug in Microsoft.DotNet.MSBuildSdkResolver, which would fall on me. You can get the resolver to trace info to stderr by setting COREHOST_TRACE=1 as demonstrated at https://github.com/OmniSharp/omnisharp-vscode/issues/1849#issuecomment-343180388
cc @akoeplinger @radical
So the first issue I see is that this mono msbuild is bundling Microsoft.NET.Sdk.Web without its Microsoft.NET.Sdk.Razor dependency.
See also Microsoft/msbuild#3829
@nguerrera Thanks for the detailed explanation! @anorborg @fogzot Can you try looking through the items Nick suggested to help us figure out what the problem is?
@nguerrera great analysis! We are now tracking this issue on Mono side as well
@nguerrera thank you for the explanation.
@rchande I think the problem is that OmniSharp uses msbuild
from the Mono distribution and Mono doesn't include Microsoft.NET.Sdk.Razor
. I don't know why but when Mono msbuild
is used, this part of the process doesn't hold true:
One in particular, Microsoft.DotNet.MSBuildSdkResolver, resolves Sdks from the .NET Core SDK location based on dotnet being on PATH.
Because my .NET Core SDK dotnet
executable is in path but gets completely ignored.
@marek-safar Do you have an issue number we can track?
@marek-safar Never mind, I see you linked it above :)
@marek-safar, is there any way I can use older version of mono
than 5.16.0 Stable
which I can use on Ubuntu 16.04
. I am still on .NET Core 1.1.0
with few projects added as a references which are full .NET 4.6.2
versions.
This all use to build properly with my Rider
on Ubuntu
; but after installing new mono, its breaking now.
Any help until above issues resolved with latest mono would be a great help. Thanks.
You'd need to check your package manager manual. If I remember correctly on Ubuntu you should be able to do something like sudo apt-get install mono-complete=<version>
to downgrade automatically.
For .deb-based distributions you'd need to use the snapshot repositories we provide: https://www.mono-project.com/docs/getting-started/install/linux/#accessing-older-releases
E.g. for Ubuntu 16.04 it'd be:
# remove existing stable mono
sudo apt remove mono-complete
sudo rm /etc/apt/sources.list.d/mono-official-stable.list
# add 5.14 snapshot repo
echo "deb https://download.mono-project.com/repo/ubuntu stable-xenial/snapshots/5.14.0 main" | sudo tee /etc/apt/sources.list.d/mono-official-snapshot.list
sudo apt update
sudo apt install mono-complete
Thanks, @marek-safar, @akoeplinger
Note : I haven't tried it, But I think another workaround is to remove your Mono Sdks grin Though that's not a wise choice if you're gonna need it.
I was having tons of issues. (Running Arch.) I gave this a go, and my problems vanished. @Marshal313 you are my hero. Seriously, why is having Mono installed from the repos such a source of problems? :(
This started to happen to me on Windows 10!! I was able to solve also by setting the environment variable MSBuildSDKsPath to point to the latest sdks folder (in my case, C:\Program Files\dotnet\sdk\2.1.500\Sdks)
Having the same issue on Windows 10, setting up the MSBuildSDKsPath did not work for me. I am using SDK 2.1.500
This happens on my system too, I'm running Manjaro (Arch)
Another sad user of Manjaro having the same issue over here...
I had the same issue in Rider, I solve it configuring .Net binary as /opt/dotnet/dotnet
. Configuring MSBuildSDKsPath
didn't help
I am running Manjaro (Arch) Following fixed it for me:
export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
sudo -E bash -c 'echo $MSBuildSDKsPath'
Fixed in Mono 5.18.0.
Thanks guys!
I got almost the same error as described. I'm on Win7. After a long time I'm back to learning Unity, got very upset cause I was used to MonoDevelop, it worked greatly. I spent all day trying to make autocomplete work properly. Tried Visual Studio, Sublime3 and Visual Studio Code, or autocomplete wouldn't work at all or it just worked for a couple of seconds... I understand things had to change but I think they should have planned it better, would be cool to have a built-in editor, like installed together with Unity and really read to go. I'm pretty sure it's trivial for experienced users but for a new student, to struggle to do something that should be simple work correctly is highly discourageous... As suggested I'm downloading the Mono 5.18.0 Preview version right now, hope it works.
Edit:
Installing Mono 5.18.0 didn't work for me.
This is the entire output:
Starting OmniSharp server at 12/31/2018, 10:37:06 AM Target: c:\Unity\Projects\Survival Shooter\Survival Shooter\Survival Shooter.sln
OmniSharp server started. Path: C:\Users\Win 7.vscode\extensions\ms-vscode.csharp-1.17.1.omnisharp\1.32.8\OmniSharp.exe PID: 10032
Starting OmniSharp on Windows 6.1.7601.65536 (x64)
DotNetPath set to dotnet
Located 1 MSBuild instance(s)
1: StandAlone 15.0 - "C:\Users\Win 7\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin"
MSBUILD_EXE_PATH environment variable set to 'C:\Users\Win 7\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin\MSBuild.exe'
Registered MSBuild instance: StandAlone 15.0 - "C:\Users\Win 7\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin"
CscToolExe = csc.exe
CscToolPath = C:\Users\Win 7\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin\Roslyn
MSBuildExtensionsPath = C:\Users\Win 7\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild
MSBuildToolsPath = C:\Users\Win 7\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin
Detecting Cake files in 'c:\Unity\Projects\Survival Shooter\Survival Shooter'.
Could not find any Cake files
Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
Detecting projects in 'c:\Unity\Projects\Survival Shooter\Survival Shooter\Survival Shooter.sln'.
Queue project update for 'c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp.csproj'
Queue project update for 'c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp-Editor.csproj'
Detecting CSX files in 'c:\Unity\Projects\Survival Shooter\Survival Shooter'.
Loading project: c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp.csproj
Could not find any CSX files
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
Configuration finished.
Omnisharp server running using Stdio at location 'c:\Unity\Projects\Survival Shooter\Survival Shooter' on host 9196.
The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
Failed to load project file 'c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp.csproj'.
c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp.csproj C:\Users\Win 7.vscode\extensions\ms-vscode.csharp-1.17.1.omnisharp\1.32.8\msbuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1126,5): Error: The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
Loading project: c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp-Editor.csproj
The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
Failed to load project file 'c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp-Editor.csproj'.
c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp-Editor.csproj C:\Users\Win 7.vscode\extensions\ms-vscode.csharp-1.17.1.omnisharp\1.32.8\msbuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1126,5): Error: The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
Attemped to update project that is not loaded: c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp.csproj
Attemped to update project that is not loaded: c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp-Editor.csproj
The csproj files are there, it just can't see them.
This part cought my attention since I have .NET v4.7.2 installed. "The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed." Couldn't install v4.5 nor uninstall v4.7.2 (tried uninstalling lots of times, uninstalling ends, it says its gone, but its always there, restarted pc several times after uninstalling and its always the same)
I'm noob but if I understood correctly there should be a way to target app to my .NET version? If so, how can I do that? (I'm using VSCode)
I can confirm that setting MSBuildSDKsPath
resolved the issue for me on Ubuntu 18.04 using the dotnet-sdk snap. For those using the snap, it might be easier to just let the dotnet
bin fill in the base path:
export MSBuildSDKsPath=`dotnet --info | grep 'Base Path' | sed -re 's/[^\/]*(.*)/\1/g'`/Sdks
which, I'd guess would work just fine for non-snap versions of dotnetcore.
@CarlosJader I don't think the problem you're encountering is related to this one. Please file a new issue so we can help you troubleshoot.
I'm using Manjaro and setting MSBuildSDKsPath
dit not solve the issue. What did solve the issue for me was copying ths Sdks
folder to mono/msbuild/15.0/bin, in my case,
cp -r /opt/dotnet/sdk/2.2.103/Sdks /usr/lib/mono/msbuild/15.0/bin
After that, OmniSharp complained about the NugetFallbackFolder
, which I created in /opt/dotnet/sdk.
mkdir /opt/dotnet/sdk/NugetFallbackFolder
Now OmniSharp doens't complain about anything and I can build my projects appropriately.
~~I'm running Manjaro, the MSBuildSDKsPath
solution didn't work for me, nor installing msbuild-stable
,
but cp -r /opt/dotnet/sdk/2.2.103/Sdks /usr/lib/mono/msbuild/15.0/bin
worked, doesn't seem a proper solution.. but it works :man_shrugging:~~
EDIT: the MSBuildSDKsPath
solution worked, read what @ehouarn-perret said below if you're having issues
@Charly6596 actually the solution given by @anticide works: export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
But you have to persist that change for every new bash instance, therefore you can put that at the end of your .bashrc
file along with what is needed for the local self-signed certificate (for proper https support in your local environment):
export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
export PATH="$PATH:/home/manjaro/.dotnet/tools"
I managed to have everything working with a Manjaro 18.02 Gnome edition on a live session. I had some other prior issues to that one: https://github.com/OmniSharp/omnisharp-vscode/issues/2837
Baby steps (similar to my other issue resolution in the link above)
Install yay
to enjoy AUR without struggling with the command line: sudo pacman -Sy yay
Setup everything you need (aka the .NET Core SDK, Mono, MSBuild and Visual Studio Code Insiders): yay -S dotnet-sdk mono binutils msbuild-stable visual-studio-code-insiders --noconfirm
yay -S dotnet-sdk mono binutils msbuild-stable visual-studio-code-bin --noconfirm
(see my second post after that one below).
binutils
cause the Gnome variant does not seem to embed that one natively, and this require for stripping in one of the steps of the msbuild-stable
installation.Add the required environment variables that you would like to export at the end of your .bashrc
file in your home folder:
export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
export PATH="$PATH:/home/manjaro/.dotnet/tools"
Create a dummy project: dotnet new mvc
Start Visual Studio Code Insiders: code-insiders .
Install the C# extension
CTRL + SHIFT + P
ext install ms-vscode.csharp
Download the .NET Code Debugger for the C# extension (if needed / not already done the first time)
CTRL + SHIFT + P
Debug: Download .NET Core Debugger
Generate the launch.json
and tasks.json
files (if not already answered yes to the popup shows: "Would you like to add the required assets to build and debug your project?")
CTRL + SHIFT + P
.NET: Generate Assets for Build and Debug
Install the tools for the development self-signed certificate
dotnet tool install --global dotnet-dev-certs
Register the development self-signed certificate:
dotnet dev-certs https
Debugging (.NET Core Launch (web)
)
CTRL + SHIFT + D
F5
@ehouarn-perret Thanks a lot, I fixed it with the following steps,
mono
, msbuild-stable
and dotnet-sdk
yay -S dotnet-sdk mono msbuild-stable
.bashrc
related to dotnet, copy pasting this:
export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
export PATH="$PATH:/home/manjaro/.dotnet/tools"
I had export PATH="$PATH:$MSBuildSDKsPath"
@Charly6596 glad to know that my solution could help you out
Playing over and over I've noticed that the insiders is not necessary: I explain everything here, in my SO answer update:
[UPDATE] The official Visual Code AUR page shows the different versions available:
The following packages provide VSCode:
- code (open-source release)
- visual-studio-code-bin AUR (Microsoft-branded release)
- code-git AUR (in-development open-source version)
I think I may have had installed the wrong version at first (the non insiders one was the open source release:
code
.Actually when playing with the official tar.gz from the website (which is the hard way equivalent of installing
visual-studio-code-bin
) it worked fine.The right way is to (obviously) go with the official Microsoft branded release:
visual-studio-code-bin
.
Does not work anymore after the last update: https://aur.archlinux.org/packages/visual-studio-code-bin
@akoeplinger @marek-safar Are there distributions of mono that include msbuild, but not Microsoft.DotNet.MSBuildSdkResolver?
I'd like to get to the bottom of why folks are resorting to setting MSBuildSdksPath. See https://github.com/dotnet/cli/issues/10865. They end up breaking themselves with every SDK update. This should not be necessary as I've explained in https://github.com/OmniSharp/omnisharp-vscode/issues/2604#issuecomment-430330103.
EDIT: https://github.com/dotnet/cli/issues/10865 was on Windows so was probably set for a different reason, but I'm still curious about why folks are needing to set this on some Linux installations.
Are there distributions of mono that include msbuild, but not Microsoft.DotNet.MSBuildSdkResolver?
@radical ?
@directhex might be able to answer this.
Yes: RHEL 6.
There are three pieces in play: Microsoft.DotNet.MSBuildSdkResolver.dll
(from msbuild.git), libhostfxr.so
(from core-setup.git), and the rest of msbuild.git. The package dependency chain is msbuild
:arrow_right: msbuild-libhostfxr
:arrow_right: msbuild-sdkresolver
In the case of our RHEL/CentOS 6 repository, the msbuild-libhostfxr
package is intentionally empty (because it cannot compile, because the available version of g++ is too old), and does not depend on msbuild-sdkresolver
since it's not functional without libhostfxr.so
I haven't re-examined this mess since 2017, maybe things have changed since then to allow the relevant library to compile with RHEL 6's neolithic g++. It's using a git snapshot of core-setup from 2017-07-06.
Setting MSBuildSDKsPath solved my problem on Fedora (vscode, .net core3 p3), but IMO a hint to set it should be added to .net core download page: https://dotnet.microsoft.com/download/thank-you/dotnet-sdk-3.0.100-preview3-linux-x64-binaries There are instructions to set PATH and DOTNET_ROOT but there is no advice to set MSBuildSDKsPath. So ultimately:
export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$DOTNET_ROOT
export MSBuildSDKsPath=$DOTNET_ROOT/sdk/$(dotnet --version)/Sdks
I seem to be doing this wrong, still not very familiar with arch-based Linux (Antergos) yet, so basically I take this export string and paste it into the terminal and press enter and it should just work?
export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
Why I think I'm doing wrong it's because code still telling me the sdks can't be found, would probably need a how-to for dummies. Using visual-studio-code-bin
from AUR.
I seem to be doing this wrong, still not very familiar with arch-based Linux (Antergos) yet, so basically I take this export string and paste it into the terminal and press enter and it should just work?
export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
No, you do need to add that line to your .bash_profile file, then reload it with: source ~/.bash_profile
A better solution would be:
export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
This way you don't have to update SDK's version.
I'm glad I did this before messing with mono
Setting MSBuildSDKsPath solved my problem on Fedora (vscode, .net core3 p3), but IMO a hint to set it should be added to .net core download page: https://dotnet.microsoft.com/download/thank-you/dotnet-sdk-3.0.100-preview3-linux-x64-binaries There are instructions to set PATH and DOTNET_ROOT but there is no advice to set MSBuildSDKsPath. So ultimately:
export DOTNET_ROOT=$HOME/dotnet export PATH=$PATH:$DOTNET_ROOT export MSBuildSDKsPath=$DOTNET_ROOT/sdk/$(dotnet --version)/Sdks
This solves my issue completely
I know there are other issues with the same behavior but they mostly refer to MacOS and the fix seems to be to install an up to date Mono. The issue I am experiencing happens on Linux, with the latest version of Mono installed.
Environment data
dotnet --info
output:VS Code version:
C# Extension version:
Mono version:
Steps to reproduce
Just load any project with latest version on Linux. The exception is always the same: