我已经通过Visual Studio的添加新项目功能创建了一个全新的“类库(桌面中的Win Ui )”库。
出于这个问题的目的,我已经将库的名称替换为<MYLIBRARY>。
在创建"xUnit测试项目“并选择".NET Core3.1(长期支持)”作为目标框架,然后将项目引用添加到类库之后,我得到了以下错误:
Error NU1201 Project <MYLIBRARY> is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project <MYLIBRARY> supports: net5.0-windows10.0.19041 (.NETCoreApp,Version=v5.0) <MYLIBRARY>.UnitTests
Error Project '..\<MYLIBRARY>\<MYLIBRARY>.csproj' targets 'net5.0-windows10.0.19041.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v3.1'. <MYLIBRARY>.UnitTests C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 1718在删除该测试项目,创建一个新的"xUnit测试项目“并选择".NET 5 (Current)”作为目标框架,然后将项目引用添加到类库之后,我得到了以下错误:
Error NU1201 Project <MYLIBRARY> is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Project <MYLIBRARY> supports: net5.0-windows10.0.19041 (.NETCoreApp,Version=v5.0) <MYLIBRARY>.UnitTests
Error Project '..\<MYLIBRARY>\<MYLIBRARY>.csproj' targets 'net5.0-windows10.0.19041.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v5.0'. <MYLIBRARY>.UnitTests C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 1718在单元测试项目的.csproj中,我尝试将<TargetFramework>net5.0</TargetFramework>更改为<TargetFramework>net5.0-windows</TargetFramework>,但没有修复任何问题。
我浏览了很多网站,但我找到了一些答案,似乎说我应该能够做我想做的事情,因为“像xUnit.net这样的单元测试框架通常不知道你的产品代码使用的库是什么。”,没有解释如果它不能工作,如何让它工作,还有一些人说我不能做我想做的事情,因为xUnit和Win Ui 3还不兼容。"WinUI 3目前不支持任何.NET单元测试框架。“
我对Stack Overflow做了一些搜索-- Win Ui / xUnit /等--但我发现的结果对我来说都没有用。
我可以对我的类库中的类运行xUnit单元测试吗?
(我可能弄混了一些东西,因为这是我的第一个Win Ui项目。)
发布于 2021-11-17 20:12:27
由于您的Win UI类库针对的是net5.0-windows10.0.19041,即.NET 5和特定于操作系统的版本,因此您的测试项目也应该针对相同的版本。
在Visual Studio中右击测试项目,选择“编辑项目文件”,并将目标框架更改为:
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>那么它就应该构建。
https://stackoverflow.com/questions/70004920
复制相似问题