项目已构建,但Omnisharp无法识别一个Nuget包,并显示错误。

3
我在Linux上(基于Ubuntu的elementaryOS)安装了.NET Core(3.0.100)和Mono(6.4.0.198)。我使用VS Code和Omnisharp扩展来进行C#开发。我正在尝试使用Xamarin.Forms构建一个示例项目
我的问题是,即使我可以使用Mono成功构建项目,但Omnisharp却抱怨缺少Xamarin.Forms引用:
The type or namespace name 'Forms' does not exist in the namespace 'Xamarin' (are you missing an assembly reference?) (CS0234)

我检查了一下,它包含在.csproj中:
<ItemGroup>
  <PackageReference Include="Xamarin.Forms" Version="4.2.0.709249" />
</ItemGroup>

我的怀疑是 Omnisharp 可能试图与 .NET Core 进行通信,而不是 Mono。 (由于我需要针对 .NET Framework 的一个版本进行目标设置,因此必须使用 Mono 进行构建。) 这是我如何使用 Mono 构建项目的方法:
$ nuget restore
$ cd GameOfLife/GameOfLife
$ msbuild
$ cd ../GameOfLife.Android
$ msbuild /t:Build,Install

我知道我不可能用.NET Core构建该项目,但我至少尝试获取nuget包:

$ 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.

最后一个错误意味着 Xamarin.Android 仅安装在 Mono 上(不可能在 .NET Core 上安装),但我不知道这是否阻止了安装 Xamarin.Forms,或者它只是一个无关的错误。
1个回答

1
问题在关闭并重新打开VS Code后消失了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接