Skip to content

Commit 8bd8359

Browse files
ANcpLuaclaude
andcommitted
fix: avoid NETSDK1023 and respect _MTPExplicitlySet in test injection
- Skip xunit injection when user already has xunit packages (prevents NETSDK1023 duplicate PackageReference warning) - Respect _MTPExplicitlySet when overriding OutputType (preserves ANCPSDK001 safety guard for MTP+Library contradiction) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0c13218 commit 8bd8359

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/Build/Common/Tests.targets

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@
2222
BeforeTargets="BeforeBuild;Restore;CollectPackageReferences"
2323
DependsOnTargets="_DetectTestFrameworksAndMTP"
2424
Condition="'$(SkipXunitInjection)' != 'true'">
25+
<!-- Check if xUnit is already present (user-supplied or from another source) -->
2526
<ItemGroup>
27+
<_ExistingXunit Include="@(PackageReference)" Condition="'%(Identity)' == 'xunit.v3' OR '%(Identity)' == 'xunit.v3.mtp-v1' OR '%(Identity)' == 'xunit.v3.mtp-v2' OR '%(Identity)' == 'xunit.v3.mtp-off'"/>
28+
</ItemGroup>
29+
<!-- Only inject if not already present (avoids NETSDK1023 duplicate warning) -->
30+
<ItemGroup Condition="'@(_ExistingXunit)' == ''">
2631
<PackageReference Include="xunit.v3.mtp-v2" Version="$(XunitMtpVersion)" VersionOverride="$(XunitMtpVersion)" IsImplicitlyDefined="true"/>
2732
</ItemGroup>
2833
<!-- Configure MTP properties since we're injecting xUnit MTP -->
2934
<PropertyGroup>
3035
<_UsesMTP>true</_UsesMTP>
3136
<_UsesXunitV3Mtp>true</_UsesXunitV3Mtp>
3237
<UseMicrosoftTestingPlatform Condition="'$(UseMicrosoftTestingPlatform)' == ''">true</UseMicrosoftTestingPlatform>
33-
<OutputType Condition="'$(OutputType)' == 'Library'">Exe</OutputType>
38+
<!-- Only auto-set OutputType if user didn't explicitly enable MTP (let safety guard warn instead) -->
39+
<OutputType Condition="'$(OutputType)' == 'Library' AND '$(_MTPExplicitlySet)' != 'true'">Exe</OutputType>
3440
<TestingPlatformDotnetTestSupport Condition="'$(TestingPlatformDotnetTestSupport)' == ''">true</TestingPlatformDotnetTestSupport>
3541
<TestingPlatformCommandLineArguments Condition="'$(TestingPlatformCommandLineArguments)' == ''">--report-xunit-trx</TestingPlatformCommandLineArguments>
3642
</PropertyGroup>

0 commit comments

Comments
 (0)