首页 > 解决方案 > 升级到 netstandard2.0 时出现 Xamarin 错误

问题描述

我正在尝试更新一个 xamarim 项目以使用 netstandard2.0。但这会产生以下错误:

严重性代码描述项目文件行抑制状态错误您的项目未引用“.NETPlatform,Version=v5.0”框架。在 project.json 的“frameworks”部分添加对“.NETPlatform,Version=v5.0”的引用,然后重新运行 NuGet 还原。

这是我的 project.json:

{
  "dependencies": {
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1",
    "NETStandard.Library": "2.0.3",
    "Newtonsoft.Json": "11.0.2",
    "System.Reactive.Linq": "4.0.0"
  },
  "frameworks": {
    "netstandard2.0": {}
  },
  "supports": {}
}

标签: .netxamarinxamarin.formscompiler-errorsvisual-studio-2017

解决方案


切换到.NET Standard 2.0可以非常简单。有很多关于它的文章,从官方文档到 youtube 视频。以下是有关如何执行此操作的几个简单步骤的简短摘要:

  1. 卸载您的 PCL 项目(右键单击 -> 卸载),然后开始编辑它(右键 -> 单击编辑)
  2. 删除 csproj 中的所有内容并插入:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <!--<PackageReference Include="" Version=""/>-->
  </ItemGroup>

</Project>

  1. 添加回 NuGet(只需打开 packages.config,然后添加上面的包引用,或通过 NuGet 包管理器。
  2. 删除 AssemblyInfo.cs(现在在 csproj 中)和 packages.config(也在 csproj 中通过 PackageReference)

来源:https

://gist.github.com/yuv4ik/063a35fe3986e62d69aee2f0ed0607bf 或者,如果您使用 Visual Studio for Mac,您可以使用Mutatio一个 VS 扩展来自动化该过程。


推荐阅读