项目生成,但 Omnisharp 看不到 nuget 包并显示错误



我在Linux(elementaryOS,基于Ubuntu(上,并且同时安装了.NET Core(3.0.100(和Mono(6.4.0.198(。对于C#开发,我使用带有Omnisharp扩展的VS Code。我正在尝试使用 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的安装,或者它只是一个无关的错误。

关闭并重新打开 VS Code 😑 后问题消失

最新更新