繁体   English   中英

无法进行单元测试 .NET MAUI Class 库

[英]Unable to unit test .NET MAUI Class Library

我有一个 .NET MAUI Class 库,我正在尝试使用 XUnit 进行单元测试。 Class 库的目标是 iOS、Android 和 Windows。我创建了一个 XUnit 测试项目,但是当我尝试运行测试时,出现以下错误:

Project targets 'net7.0-windows10.0.19041.0;net7.0-windows10.0.22621.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v7.0'

我要测试的项目的 My.csproj 文件具有以下代码:

<PropertyGroup>
    <TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst;net7.0</TargetFrameworks>
    <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">net7.0-windows10.0.19041.0</TargetFrameworks>
    <UseMaui>true</UseMaui>
    <SingleProject>true</SingleProject>
    <ImplicitUsings>enable</ImplicitUsings>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
    <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
    <Platforms>AnyCPU;x86;x64;ARM64;ARM32</Platforms>
</PropertyGroup>

如果我删除该行

<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">net7.0-windows10.0.19041.0</TargetFrameworks>

我可以运行单元测试,但我无法在 Windows 上运行我的 MAUI 项目。

我究竟做错了什么? 任何帮助将不胜感激

Go to .Net Maui project .csproj ,替换下面代码

<OutputType>Exe</OutputType>

<OutputType Condition="'$(TargetFramework)' != 'net7.0'">Exe</OutputType>

感谢@LiqunShen-MSFT 我发现通过将我的测试项目中的以下行从:.net7.0 更改为:.net7.0-windows10.0.19041.0 它解决了我的问题

暂无
暂无

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

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