【问题标题】:Errors when trying to use netstandard with Xamarin forms尝试将 netstandard 与 Xamarin 表单一起使用时出错
【发布时间】:2016-07-27 08:14:53
【问题描述】:

所以我一直在尝试制作一个将使用 netstandard 类库公共代码的项目,但是由于我不断遇到错误,我一直没有成功。我一直在关注https://oren.codes/2016/07/09/using-xamarin-forms-with-net-standard/https://xamarinhelp.com/dot-net-standard-pcl-xamarin-forms/ 的帖子,了解如何操作。他的示例我可以下载并正常运行,但是当我尝试按照他的说明复制它时,我遇到了错误

您的项目未引用“.NETPortable,Version=v4.5,Profile=Profile111”框架。在 project.json 的“frameworks”部分添加对“.NETPortable,Version=v4.5,Profile=Profile111”的引用,然后重新运行 NuGet 还原。 FixMyCity.Mobile C:\Program Files (x86)\MSBuild\Microsoft\NuGet\Microsoft.NuGet.targets 140

我知道这听起来很明显;只需在 project.json 的 frameworks 部分添加.NETPortable,Version=v4.5,Profile=Profile111,然后我就会收到此错误(80% 肯定这是由于添加它引起的,因为否则它不存在)

包含 MSBuild 目标和 props 文件的包不能完全安装在面向多个框架的项目中。 MSBuild 目标和道具文件已被忽略。 ...project.nuget.targets

另外,当我查看示例项目时,他没有针对 .NETPortable,Version=v4.5,Profile=Profile111,它工作正常

如果您想看一下,这是迄今为止我最接近的:https://github.com/Toxicable/XamarinFormsNetstandardIssue
它只是应用了以下步骤的模板项目(Xamrin 表单 protalble)

  1. 运行 `PM> 在每个项目上卸载-Package xamarin.forms -Force -RemoveDependencies; IOS 和 Andriod 先 PCL 最后。
  2. 根据控制台提示重启VS
  3. 在每个项目中添加project.json,如下所示
  4. 尝试构建,但它不会

PCL 项目.json

{
  "supports": {},
  "dependencies": {
    "Xamarin.Forms": "2.3.0.107",
    "NETStandard.Library": "1.6.0"
  },
  "frameworks": {
    "netstandard1.1": {
      "imports": "portable-net45+win8+wpa81+wp8"
    },
    ".NETPortable,Version=v4.5,Profile=Profile111": {}
  }
}

project.Driod project.json

{
  "dependencies": {
  },
  "frameworks": {
    "MonoAndroid,Version=v6.0": {
    }
  },
  "runtimes": {
    "win": {}
  }
}

project.iOS project.json

{
  "dependencies": {
  },
  "frameworks": {
    "Xamarin.iOS,Version=v1.0": {
    }
  },
  "runtimes": {
    "win": {}
  }
}

【问题讨论】:

  • 您看过关于 Cycle 7 Service Release 1 的说明吗? releases.xamarin.com/… 这些构建引入了与新的 .NET Standard 1.6 的兼容性。这尤其允许开发人员使用针对 .NET Standard 1.6 构建的 NuGet 包。
  • @JonDouglas我已经看到了,我不确定这与我的问题有什么关系,我的目标是低网络标准,因为它是最兼容的,但会变成我可以针对 iOS 的最高标准Andriod 是 1.6,我认为一旦项目实际构建完成

标签: c# xamarin xamarin.forms


【解决方案1】:

我下载了您的项目并注意到 Xamarin Forms 可移植库看起来有点奇怪,您通常会在参考中看到带有蓝色图标的 Xamarin Forms 和 .NET 标准库。

我不确定它是如何发生的,但这是你如何解决它的。

  1. 从您的 project.json 中删除 ".NETPortable,Version=v4.5,Profile=Profile111": {}

  2. 卸载您的项目

  3. 编辑项目文件

  1. 删除此行<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>

  2. 将 v4.5 更改为 v5.0 <TargetFrameworkVersion>v5.0</TargetFrameworkVersion>

  3. 保存文件并重新加载项目,它现在无需 Profile111 即可构建,并且还将显示参考

【讨论】:

  • 这正是问题所在,非常感谢您花时间指出这一点,也不确定它是如何发生的,但我希望其他遇到此问题的人可以在这里找到答案跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-12
  • 2014-03-29
  • 2019-08-24
  • 2012-10-30
  • 2021-04-02
相关资源
最近更新 更多