【发布时间】:2020-02-09 16:57:52
【问题描述】:
我在 linux 上(elementaryOS,基于 Ubuntu)并安装了 .NET Core (3.0.100) 和 Mono (6.4.0.198)。对于 C# 开发,我使用带有 Omnisharp 扩展名的 VS Code。我正在尝试使用 Xamarin.Forms 构建 sample project。
我的问题是,即使 我可以使用 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,或者它是否只是一个不相关的错误。
【问题讨论】:
标签: .net xamarin.forms .net-core mono omnisharp