Skip to content

Ship Microsoft.NET.Test.Sdk.props at the buildMultiTargeting root - #16412

Open
Jakub Jareš (nohwnd) wants to merge 1 commit into
microsoft:mainfrom
nohwnd:nohwnd-fix-test-sdk-buildmultitargeting-layout
Open

Ship Microsoft.NET.Test.Sdk.props at the buildMultiTargeting root#16412
Jakub Jareš (nohwnd) wants to merge 1 commit into
microsoft:mainfrom
nohwnd:nohwnd-fix-test-sdk-buildmultitargeting-layout

Conversation

@nohwnd

Copy link
Copy Markdown
Member

buildMultiTargeting/<PackageId>.props is what NuGet imports into the outer build of a multi-targeting project. The outer build has no TargetFramework, so it cannot resolve a TFM subfolder. We shipped the props only as buildMultiTargeting/net8.0/, net462/, netcoreapp2.0/ and netstandard2.0/, and nothing at the root, so the outer build imported nothing at all. TestProject, IsTestProject and the TestContainer capability were never set there. Pack reads IsPackable on the outer build, so a test project with <TargetFrameworks> produces a .nupkg.

This is a regression from the Arcade port. The hand-written nuspec had <file src="Microsoft.NET.Test.Sdk.props" target="buildMultiTargeting\" /> at the root, and no .targets there at all.

The props now goes to the buildMultiTargeting root and the four TFM subfolder copies are gone. I removed them rather than leaving them, because a dead copy of the unsupported-TFM shim under buildMultiTargeting/netstandard2.0/ reads like it can fire on an outer build, and it cannot. build/<tfm>/ is untouched. No .targets goes to the root: Microsoft.NET.Test.Sdk.targets is the unsupported-TFM shim and its InitialTargets error has no TargetFramework condition, so it would fail every outer build.

verify-nupkgs.ps1 only counted entries. Moving a file from one folder to another keeps the count the same, which is why this was invisible. It now also checks that the props sits at the buildMultiTargeting root, and that no file hides in a subfolder there.

Verified on a multi-targeting test project, reading the outer build evaluation out of a binlog:

IsTestProject (outer) IsPackable (outer) dotnet pack
17.14.1, as shipped unset true produces a package
this change true false produces nothing

Same result for <Project Sdk="MSTest.Sdk/4.0.1"> with UseVSTest, which is the shape from the issue, and on both the 9.0.317 and 10.0.303 SDKs. Microsoft.NET.Test.Sdk goes from 26 files to 21; eng/expected-nupkg-file-counts.json is regenerated from a clean Release pack build. Reverting the csproj and re-running verify-nupkgs.ps1 fails with exit code 1.

Fix #15309

🤖

NuGet imports buildMultiTargeting/<PackageId>.props into the outer build of a
multi-targeting project. The outer build has no TargetFramework, so a copy under
buildMultiTargeting/<tfm>/ is never resolved. We only shipped the TFM subfolders,
so the outer build imported nothing and TestProject, IsTestProject and the
TestContainer capability were never set there. NuGet reads IsPackable on the outer
build, which is why a test project with <TargetFrameworks> packs.

Put the props at the buildMultiTargeting root and drop the four TFM subfolder
copies, which matches the layout the hand-written nuspec had before the Arcade
port. No .targets goes to the root: Microsoft.NET.Test.Sdk.targets is the
unsupported-TFM shim and its InitialTargets error is unconditional, so it would
fail every outer build.

verify-nupkgs.ps1 only counted entries, and moving a file between folders leaves
the count unchanged, which is why this went unnoticed. It now also asserts that
the props sits at the buildMultiTargeting root and that nothing hides in a
subfolder there.

Fix microsoft#15309

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a packaging regression in Microsoft.NET.Test.Sdk where the outer build of multi-targeting projects (which has no $(TargetFramework)) was not importing any buildMultiTargeting/<PackageId>.props, causing IsTestProject not to be set and dotnet pack to incorrectly produce a .nupkg for test projects.

Changes:

  • Ship Microsoft.NET.Test.Sdk.props at buildMultiTargeting/ folder root (and remove the ineffective buildMultiTargeting/<tfm>/ copies).
  • Stop shipping the unsupported-TFM shim .targets under buildMultiTargeting/ (to avoid unconditional outer-build failures).
  • Strengthen eng/verify-nupkgs.ps1 to validate package layout (not just file counts), specifically enforcing correct buildMultiTargeting placement and preventing hidden subfolder content.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/package/Microsoft.NET.Test.Sdk/Microsoft.NET.Test.Sdk.csproj Moves the shipped .props into buildMultiTargeting/ root and removes dead buildMultiTargeting/<tfm>/ entries to ensure the outer build imports it.
eng/verify-nupkgs.ps1 Adds package layout verification to detect incorrect buildMultiTargeting placement that a file-count-only check cannot catch.
eng/expected-nupkg-file-counts.json Updates the expected file count for Microsoft.NET.Test.Sdk after removing redundant package entries.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSTest.Sdk/4.0.1 is packable by default and creates a NuGet package.

2 participants