简体   繁体   English

在我的解决方案中将参考项目winform添加到我的单元测试项目会导致“参考错误”

[英]Add reference project winform to my unit test project in my solution causes "reference error"

I create a Winform project with c# in VS2022 with target framework '.net 6.0', target OS: windows with minimum OS version 7. I want to "Unit Test" the project, so I add a new unit test project to the solution and when I reference the AppUpdate project to the unit test project (under dependencies of the unit test project, right clic, add project reference, add AppUpdate) show an exclamation mark(:) and when I build the solution give me this error:我在 VS2022 中使用 c# 创建了一个 Winform 项目,目标框架为“.net 6.0”,目标操作系统:windows,最低操作系统版本为 7。我想对项目进行“单元测试”,所以我在解决方案中添加了一个新的单元测试项目,当我将 AppUpdate 项目引用到单元测试项目时(在单元测试项目的依赖项下,右键 clic,添加项目引用,添加 AppUpdate)显示一个感叹号(:),当我构建解决方案时给我这个错误:

Severity Code Description Project File Line Suppression State Error Project '..\AppUpdate\AppUpdate.csproj' targets 'net6.0-windows'.严重性代码描述项目文件行抑制 State 错误项目“..\AppUpdate\AppUpdate.csproj”针对“net6.0-windows”。 It cannot be referenced by a project that targets '.NETCoreApp,Version=v6.0'.以“.NETCoreApp,Version=v6.0”为目标的项目不能引用它。 ServerUpdateTest C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets 1806 ServerUpdateTest C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets 1806

I try different kind of unit test project, but is always the same.我尝试了不同类型的单元测试项目,但总是一样的。 The projects templates I have tried are:我尝试过的项目模板是:

  1. xUnit test project xUnit 测试项目
  2. MSTest test project MSTest 测试项目
  3. Unit Test Project (.NET Framework)单元测试项目(.NET 框架)

I found something similar but is not the same problem: Your project does not reference ".NETFramework,Version=v4.6.2" framework.我发现了类似但不是同一个问题: 您的项目没有引用“.NETFramework,Version=v4.6.2”框架。 Add a reference to ".NETFramework,Version=v4.6.2" in the "TargetFrameworks" 在“TargetFrameworks”中添加对“.NETFramework,Version=v4.6.2”的引用

My project 'AppUpdate' have the target to minimal SO 'Win 7' and all the unit test templates have target to any SO.我的项目“AppUpdate”的目标是最小的 SO“Win 7”,所有的单元测试模板都指向任何 SO。

the solution is go to properties of the Unit Test project and change the target SO to Windows and version to 7.解决方案是将 go 更改为单元测试项目的属性,并将目标 SO 更改为 Windows 并将版本更改为 7。

and that will make the unit test to work property.这将使单元测试发挥作用。

Cheers.干杯。

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

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