@@ -672,4 +672,71 @@ public void TestMethod1()
672672 testHostResult . AssertOutputContains ( "Test Parallelization enabled" ) ;
673673 testHostResult . AssertOutputContains ( "(Workers: 3, Scope: MethodLevel)" ) ;
674674 }
675+
676+ // Verifies that MSTest.Sdk can be layered on top of a different base SDK (here Microsoft.NET.Sdk.Web)
677+ // using manual SDK imports without emitting MSB4011 duplicate-import warnings. See https://github.com/microsoft/testfx/issues/9562.
678+ [ TestMethod ]
679+ public async Task MSTestSdk_LayeredOnTopOfWebSdk_BuildsWithoutDuplicateImportWarnings ( )
680+ {
681+ const string MixedSdkSource = """
682+ #file MSTestWeb.csproj
683+ <Project>
684+
685+ <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk.Web" />
686+ <Import Project="Sdk.props" Sdk="MSTest.Sdk" />
687+
688+ <PropertyGroup>
689+ <EnableMicrosoftTestingPlatform>true</EnableMicrosoftTestingPlatform>
690+ <TargetFramework>$TargetFramework$</TargetFramework>
691+ <PlatformTarget>x64</PlatformTarget>
692+ <NoWarn>$(NoWarn);NU1507</NoWarn>
693+ </PropertyGroup>
694+
695+ <Import Project="Sdk.targets" Sdk="MSTest.Sdk" />
696+ <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk.Web" />
697+
698+ </Project>
699+
700+ #file global.json
701+ {
702+ "msbuild-sdks": {
703+ "MSTest.Sdk": "$MSTestVersion$"
704+ }
705+ }
706+
707+ #file UnitTest1.cs
708+ using Microsoft.AspNetCore.Builder;
709+ using Microsoft.VisualStudio.TestTools.UnitTesting;
710+
711+ namespace MSTestWebTest
712+ {
713+ [TestClass]
714+ public class UnitTest1
715+ {
716+ [TestMethod]
717+ public void TestMethod1()
718+ {
719+ WebApplicationBuilder builder = WebApplication.CreateBuilder();
720+ Assert.IsNotNull(builder);
721+ }
722+ }
723+ }
724+ """ ;
725+
726+ const string MixedAssetName = "MSTestWeb" ;
727+
728+ using TestAsset testAsset = await TestAsset . GenerateAssetAsync (
729+ MixedAssetName ,
730+ MixedSdkSource
731+ . PatchCodeWithReplace ( "$MSTestVersion$" , MSTestVersion )
732+ . PatchCodeWithReplace ( "$TargetFramework$" , TargetFrameworks . NetCurrent ) ) ;
733+
734+ DotnetMuxerResult compilationResult = await DotnetCli . RunAsync ( $ "build -c { BuildConfiguration . Release } { testAsset . TargetAssetPath } ", cancellationToken : TestContext . CancellationToken ) ;
735+ compilationResult . AssertExitCodeIs ( 0 ) ;
736+ compilationResult . AssertOutputDoesNotContain ( "MSB4011" ) ;
737+
738+ var testHost = TestHost . LocateFrom ( testAsset . TargetAssetPath , MixedAssetName , TargetFrameworks . NetCurrent , buildConfiguration : BuildConfiguration . Release ) ;
739+ TestHostResult testHostResult = await testHost . ExecuteAsync ( cancellationToken : TestContext . CancellationToken ) ;
740+ testHostResult . AssertOutputContainsSummary ( 0 , 1 , 0 ) ;
741+ }
675742}
0 commit comments