配置Xunit后运行dotnet test出现重复属性错误求助
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

