简体   繁体   English

Xamarin项目未正确从共享库继承

[英]Xamarin projects not inheriting from shared library correctly

I've started working with Xamarin Forms using the .NET Standard. 我已经开始使用.NET Standard处理Xamarin Forms。 When trying to use a dependency injection for platform specific code (in this case, different code for Android and iOS), the project can not find the interface from the base project. 当尝试对平台特定的代码(在这种情况下,Android和iOS使用不同的代码)使用依赖项注入时,项目无法从基础项目中找到接口。

I was following a guide with an example shown below 我正在按照以下示例显示指南 在此处输入图片说明

However Visual Studio does not find my interface from the base project in the Android / iOS projects. 但是,Visual Studio在Android / iOS项目的基础项目中找不到我的界面。

在此处输入图片说明

The namespace can not be found either. 找不到名称空间。 The only one it finds is ProblemCode.Android. 它找到的唯一一个是ProblemCode.Android。 How would I fix this issue? 我该如何解决这个问题?

I don't see a reference to the your shared project in the last image. 我没有在上一张图片中看到对您共享项目的引用。

However, i have noticed with .NetStandard , Xamarin gets confused sometimes, Though it can get confused at the best of times for no reason at all. 但是,我注意到使用.NetStandard时Xamarin有时会感到困惑,尽管它可能在最佳情况下毫无理由地变得混乱。

Usually when i have benign problem with Xamarin i try the following sets. 通常,当我对Xamarin有良性问题时,请尝试以下方法。

  • Clean the solution 清洁溶液
    • Clear the Bin and Obj directories of all projects. 清除所有项目的Bin和Obj目录。
    • Clean the solution 清洁溶液
    • Restart visual studio 重新启动Visual Studio
    • Rebuild the solution 重建解决方案
  • Sometimes i have needed to Remove/Add the references to the shared .NetStandard projects back to the Device Projects 有时我需要删除/将对共享.NetStandard项目的引用添加/添加回Device Projects
    • Maybe make sure it builds independently without problems 也许要确保它独立构建没有问题
  • In some cases (probably not this one) it helps to Reinstall all nugets 在某些情况下(可能不是这种情况),它有助于重新安装所有nuget

Note : I'm not sure this will help you in your case, but it was at least worth mentioning 注意 :我不确定这是否对您有帮助,但这至少值得一提

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM