You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

配置Xunit后运行dotnet test出现重复属性错误求助

Fixing Duplicate TargetFrameworkAttribute Error When Running dotnet test

Here are the actionable steps to resolve your issue:

  • Remove xunit from the main project: Your main app (Proj.csproj) doesn't need the xunit package reference—only the test project does. Delete this line from the main project's ItemGroup:

    <PackageReference Include="xunit" Version="2.7.1" />
    

    Having xunit in the main project can trigger conflicting build logic that leads to duplicate attribute generation.

  • Disable auto-generated TargetFrameworkAttribute in the test project: If the error persists, add this property to the PropertyGroup in Proj.Tests.csproj:

    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
    

    This prevents the test project from generating its own TargetFrameworkAttribute, which conflicts with the one from the main project.

  • Clean and rebuild: After making these changes, run these commands to ensure a fresh build:

    dotnet clean
    dotnet build
    dotnet test
    

This issue usually arises when multiple projects in the solution generate identical auto-generated assembly attributes. Removing unnecessary dependencies and disabling redundant attribute generation should resolve the conflict.

内容的提问来源于stack exchange,提问作者paul h

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 19:27:43