Summary
MSTest.Sdk implicitly imports Microsoft.NET.Sdk as its base SDK (both Sdk/Sdk.props.template and Sdk/Sdk.targets do <Import ... Sdk=""Microsoft.NET.Sdk"" />). This means it can't be used as the outer <Project Sdk=""...""> for projects that need a different base SDK such as Microsoft.NET.Sdk.Web (ASP.NET Core integration test projects).
A workaround is to hand-write the SDK imports for both SDKs instead of using the Sdk attribute:
<Project>
<Import Project=""Sdk.props"" Sdk=""Microsoft.NET.Sdk.Web"" />
<Import Project=""Sdk.props"" Sdk=""MSTest.Sdk"" />
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<Import Project=""Sdk.targets"" Sdk=""MSTest.Sdk"" />
<Import Project=""Sdk.targets"" Sdk=""Microsoft.NET.Sdk.Web"" />
</Project>
This functionally works — the project restores, builds, references ASP.NET Core (WebApplication.CreateBuilder()), and runs under the MSTest runner (Passed! Failed: 0, Passed: 2). However, because both MSTest.Sdk and Microsoft.NET.Sdk.Web each import Microsoft.NET.Sdk, the build emits duplicate-import warnings:
warning MSB4011: "...\Microsoft.NET.Sdk\Sdk\Sdk.props" cannot be imported again.
It was already imported at "...\Microsoft.NET.Sdk.Web\Targets\Sdk.Server.props".
This is most likely a build authoring error. This subsequent import will be ignored.
Ask
Explore whether we can make the mixed/manual-import scenario clean, e.g.:
- Guard our base-SDK import with a condition that skips it when
Microsoft.NET.Sdk (or a derived SDK such as Microsoft.NET.Sdk.Web) has already been imported (for example, check a well-known property set by the base SDK props), or
- Provide a documented, first-class way to layer
MSTest.Sdk on top of a different base SDK without the MSB4011 noise.
Context
Came up while reviewing dotnet/docs#54554, which documents that MSTest.Sdk can't replace a different base SDK and recommends configuring MSTest manually for such projects. It would be nice if combining SDKs were a supported, warning-free path.
Summary
MSTest.Sdkimplicitly importsMicrosoft.NET.Sdkas its base SDK (bothSdk/Sdk.props.templateandSdk/Sdk.targetsdo<Import ... Sdk=""Microsoft.NET.Sdk"" />). This means it can't be used as the outer<Project Sdk=""..."">for projects that need a different base SDK such asMicrosoft.NET.Sdk.Web(ASP.NET Core integration test projects).A workaround is to hand-write the SDK imports for both SDKs instead of using the
Sdkattribute:This functionally works — the project restores, builds, references ASP.NET Core (
WebApplication.CreateBuilder()), and runs under the MSTest runner (Passed! Failed: 0, Passed: 2). However, because bothMSTest.SdkandMicrosoft.NET.Sdk.Webeach importMicrosoft.NET.Sdk, the build emits duplicate-import warnings:Ask
Explore whether we can make the mixed/manual-import scenario clean, e.g.:
Microsoft.NET.Sdk(or a derived SDK such asMicrosoft.NET.Sdk.Web) has already been imported (for example, check a well-known property set by the base SDK props), orMSTest.Sdkon top of a different base SDK without theMSB4011noise.Context
Came up while reviewing dotnet/docs#54554, which documents that
MSTest.Sdkcan't replace a different base SDK and recommends configuring MSTest manually for such projects. It would be nice if combining SDKs were a supported, warning-free path.