Search code examples
.netxamarin.forms.net-coremonoomnisharp

Project builds but Omnisharp doesn't see a nuget package and shows error


I'm on linux (elementaryOS, Ubuntu-based) and have both .NET Core (3.0.100) and Mono (6.4.0.198) installed. For C# development I use VS Code with the Omnisharp extension. I'm trying to build a sample project using Xamarin.Forms.

My problem is that even though I can successfully build the project with Mono, Omnisharp is complaining about a missing Xamarin.Forms reference:

The type or namespace name 'Forms' does not exist in the namespace 'Xamarin' (are you missing an assembly reference?) (CS0234)

I checked it, and it is included in the .csproj:

<ItemGroup>
  <PackageReference Include="Xamarin.Forms" Version="4.2.0.709249" />
</ItemGroup>

My suspition is that maybe Omnisharp tries to communicate with .NET Core instead of Mono. (Since I need to target a version of .NET Framework, I have to build it with Mono.) This is how I build the project with Mono:

$ nuget restore
$ cd GameOfLife/GameOfLife
$ msbuild
$ cd ../GameOfLife.Android
$ msbuild /t:Build,Install

I know I can't possibly build the project with .NET Core, but I tried at least fetching nuget packages:

$ dotnet restore
→ ./GameOfLife/GameOfLife/GameOfLife.Android/GameOfLife.Android.csproj :
  warning NU1503: Skipping restore for project './GameOfLife/GameOfLife
  /GameOfLife.Android/GameOfLife.Android.csproj'. The project file may be
  invalid or missing targets required for restore. [./GameOfLife/GameOfLife.sln]

$ cd GameOfLife/GameOfLife.Android
$ dotnet restore
→ (nothing happened)

$ dotnet add GameOfLife.Android.csproj package Xamarin.Forms
→ ./GameOfLife/GameOfLife/GameOfLife.Android/GameOfLife.Android.csproj(85,3):
  error MSB4019: The imported project "/usr/share/dotnet/sdk/3.0.100/Xamarin
  /Android/Xamarin.Android.CSharp.targets" was not found. Confirm that the path
  in the <Import> declaration is correct, and that the file exists on disk.
→ Unable to create dependency graph file for project 'GameOfLife.Android.csproj'.
  Cannot add package reference.

The last error means that Xamarin.Android is only installed for Mono (it's not possible to install it for .NET Core), but I don't know whether this is blocking the installation of Xamarin.Forms, or whether it's just an urelated error.


Solution

  • The issue is gone after closing and reopening VS Code 😑