尝试将netstandard与Xamarin表单一起使用时出错

时间:2016-07-26 05:29:08

标签: c# xamarin xamarin.forms

所以我一直在尝试制作一个使用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"框架。添加对" .NETPortable,Version = v4.5,Profile = Profile111"的引用在"框架" project.json的一部分,然后重新运行NuGet还原。 FixMyCity.Mobile C:\ Program Files(x86)\ MSBuild \ Microsoft \ NuGet \ Microsoft.NuGet.targets 140

我知道这听起来很明显;只需在project.json的框架部分添加.NETPortable,Version=v4.5,Profile=Profile111但是我得到了这个错误(80%确定它是由于添加它而引起的,因为它不存在)

  

包含MSBuild目标和道具文件的软件包无法在针对多个框架的项目中完全安装。 MSBuild目标和道具文件已被忽略。 ... project.nuget.targets

另外,当我查看示例项目时,他没有定位.NETPortable,Version=v4.5,Profile=Profile111并且工作正常

如果你想看一下,这是我到目前为止最接近的那个:https://github.com/Toxicable/XamarinFormsNetstandardIssue
它只是模板项目(Xamrin形成protalble),并采用以下步骤

  1. 运行`PM>每个项目的卸载 - 包xamarin.forms -Force -RemoveDependencies; IOS和Andriod第一次PCL持续。
  2. 根据控制台
  3. 的提示重新启动VS.
  4. project.json添加到每个项目中,如下所示
  5. 尝试构建,但它不会
  6. PCL project.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": {}
      }
    }
    

1 个答案:

答案 0 :(得分:1)

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

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

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

  2. 卸载您的项目

  3. 编辑项目文件

  4. enter image description here

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

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

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

    4. enter image description here

相关问题