This problem occurs if I install dotnet from the Ubuntu 19.04 repositories. If I instead install from the Microsoft site, the problem does not occur. I don't know if this is an OmniSharp issue, or an Ubuntu packaging issue. So I'll start here, and if the issue belongs to Ubuntu, please let me know and Ill take it there.
Install dotnet-sdk-2.2 from the 19.04 repo. Then install Visual Studio Code from package code_1.36.1-1562627527_amd64.
IMPORTANT: After installing Visual Studio Code, start it up, and change the setting Omnisharp: Use Global Mono to "Never".
Set up GtkSharp with "dotnet new -i "GtkSharp.Template.CSharp"
Then create a GtkSharp app with "dotnet new gtkapp", and try to run it without debugging (or just build it from the terminal.)
App should build and run.
Failed to load project file '/data/projects/dotnet/GtkApp/GtkApp.csproj'.
/data/projects/dotnet/GtkApp/GtkApp.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "/usr/lib/mono/xbuild/15.0/Microsoft.Common.props" was not found. Confirm that the path in the
Now, in Sdk.props, I see the following line for loading Microsoft.Common.props:
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />`
If I change this instead to:
<Import Project="/usr/share/dotnet/sdk/2.2.301/Current/Microsoft.Common.props" />
then everything builds and runs fine. So, something is not setting the MSBuild environment variables correctly. I'm not familiar wtih MSBuild, so I can't figure out where those are constructed. Notice it is picking up the correct instance of Sdk.props from /usr/share/dotnet, but then attempting to load Microsoft.Common.props from /usr/lib/mono. But it shouldn't be doing that, since I told Code to never use Global Mono.
Failed to load project file '/data/projects/dotnet/GtkApp/GtkApp.csproj'.
/data/projects/dotnet/GtkApp/GtkApp.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "/usr/lib/mono/xbuild/15.0/Microsoft.Common.props" was not found. Confirm that the path in the
Nothing
VSCode version: 1.36.1
C# Extension: 1.20.0
Mono Information
OmniSharp using built-in mono
Dotnet Information
.NET Core SDK (reflecting any global.json):
Version: 2.2.301
Commit: 70d6be0814
Runtime Environment:
OS Name: ubuntu
OS Version: 19.04
OS Platform: Linux
RID: ubuntu.19.04-x64
Base Path: /usr/share/dotnet/sdk/2.2.301/
Host (useful for support):
Version: 2.2.6
Commit: 7dac9b1b51
.NET Core SDKs installed:
2.2.301 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
Visual Studio Code Extensions
|Extension|Author|Version|
|---|---|---|
|csharp|ms-vscode|1.20.0|;
I am also experiencing the same issues. After I use this hotfix solution for the Sdk.props file, it fixes OmniSharp for my VSCode.
I have the same environment setup as the OP.
@Vulfox
I am having the same issue. What hotfix solution you are talking about?
@ar-tour , it is written in the OP's post under the "Actual Behavior" title. It mentions changing this file /usr/share/dotnet/sdk/2.2.301/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props by replacing the interpolated path to a hardcoded path.
I am having the same issue but on NixOS, where I cannot edit Sdk.props as it is installed on a read-only file system.
I'm having the same problem with .net core projects on NixOS.
I'm using nix-shell --pure and then running code .
shell.nix
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "my-environment";
buildInputs = [
pkgs.dotnet-sdk
pkgs.vscode
pkgs.mono
pkgs.dotnetPackages.Nuget
];
}
I installed the latest mono (6.0.0) and told vscode to use the global mono and this was resolved
Editing the Sdk.props file for 2.2 worked for me, but the problem returned when I switched to 3.0, and editing the Sdk.props file no longer resolves it.
OS: Ubuntu Mate 19.04 (Disco Dingo)
Kernel: 5.0.0-29
.NET Core: 3.0.100
@jfcarr I just started up my Ubuntu Mate 19.04 VM, and installed .Net Core 3.0 SDK using the Package Manager instructions from here: https://dotnet.microsoft.com/download/dotnet-core/3.0
The workaround mentioned here is no longer needed. With 3.0, the app built and ran for me without having to modify any of the props files. The SDK installed to /usr/share/dotnet/sdk/3.0.100/.
@guy-rouillier I installed it the same way, but the error occurs for me. Perhaps a carry-over of the 2.2 issue, since I had it installed previously.
I also had 2.2 installed, and still do as a matter of fact. Have you changed the TargetFramework to netcoreapp3.0?
<TargetFramework>netcoreapp3.0</TargetFramework>
If so, the 2.2 props settings should not come into play.
I got it working. In addition to editing Sdk.props, I also had to set this environment variable:
export MSBuildSDKsPath=/usr/share/dotnet/sdk/3.0.100/Sdks
Things start working as soon as I move /usr/lib/mono/xbuild away from there, so apparently something within OmniSharp's msbuild still looks in the global paths, even if the bundled version is being used.
I have the same issue (macOS). If anyone needs a repro, it happens on https://github.com/felixfbecker/PowerGit. I don't have mono installed at all, only .NET Core (several versions including v3).
I get a very similar issue with the following error when trying to load a .net core project within a Unity C# solution on OSX:
Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "/Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/xbuild/Current/Microsoft.Common.props" was not found. Also, tried to find "Current/Microsoft.Common.props" in the fallback search path(s) for $(MSBuildExtensionsPath) - "/Library/Frameworks/Mono.framework/External/xbuild/" . These search paths are defined in "/Users/[username]/.vscode/extensions/ms-vscode.csharp-1.21.8/.omnisharp/1.34.8/omnisharp/OmniSharp.exe.config". Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths. /usr/local/share/dotnet/sdk/2.2.300/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props
I resolved it by installing the lastest version of Mono
Installing Mono on MacOS helped me as well.
My fix for error in adrianwilczynski.add-reference:
Re: [GitHub Developer Support] - Microsoft.Common.Props not found -FIX
....vscode\extensions\ms-dotnettools.csharp-1.21.15.omnisharp\1.34.14.msbuild\Current\Microsoft.Common.Props
copy to
...\ProgramFiles\MSBuild\Current
JR
Most helpful comment
I get a very similar issue with the following error when trying to load a .net core project within a Unity C# solution on OSX:
Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "/Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/xbuild/Current/Microsoft.Common.props" was not found. Also, tried to find "Current/Microsoft.Common.props" in the fallback search path(s) for $(MSBuildExtensionsPath) - "/Library/Frameworks/Mono.framework/External/xbuild/" . These search paths are defined in "/Users/[username]/.vscode/extensions/ms-vscode.csharp-1.21.8/.omnisharp/1.34.8/omnisharp/OmniSharp.exe.config". Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths. /usr/local/share/dotnet/sdk/2.2.300/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.propsI resolved it by installing the lastest version of Mono