无法使用Xamarin Forms安装NUnit

时间:2017-11-17 16:32:42

标签: visual-studio xamarin.forms nuget nunit

我试图在我的Xamarin Forms项目中安装NUnit软件包,但我收到此错误:

   Severity Code Description Project File Line Suppression State
   Error Could not install package 'NUnit 3.9.0'. You are trying to install 
   this package into a project that targets 
   '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not 
   contain any assembly references or content files that are compatible with 
   that framework. For more information, contact the package author. 0

我正在使用Visual Studio 2017和Windows 10。

有没有人对此问题有任何经验?看起来奇怪的是,这样一个普通的包装可能会出现这样的错误...

非常感谢!

2 个答案:

答案 0 :(得分:2)

NUnit 3.9不包含任何与可移植类库(PCL)项目兼容的程序集。它有一个.NET Standard 1.3程序集,但.NETStandard version 1.3 is not compatible with any PCL profiles

所以你的选择是:

  1. 按照Nkosi的建议使用较旧的NUnit NuGet版本,例如2.6.4。
  2. 将您的PCL项目转换为.NET标准项目。
  3. 在面向完整.NET Framework的项目中创建NUnit测试,并让测试项目引用PCL项目。

答案 1 :(得分:0)

Visual Studio适配器和NUnit控制台无法运行基于Xamarin的测试,因为它们都基于完整框架。但是,您可以使用NUnit Xamarin运行器在设备上运行。请参阅Testing Xamarin Projects using NUnit

就个人而言,我发现在测试项目中定位.NET 4.5.x并引用您正在测试的Xamarin PCL项目要容易得多。这允许您使用最新版本的NUnit并在Visual Studio或命令行中运行测试。有关详细信息,请参阅tooltip