Skip to content

Explore reducing MSB4011 duplicate-import warnings when MSTest.Sdk is combined with another base SDK #9562

Description

@Evangelink

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions