Ship Microsoft.NET.Test.Sdk.props at the buildMultiTargeting root - #16412
Open
Jakub Jareš (nohwnd) wants to merge 1 commit into
Open
Ship Microsoft.NET.Test.Sdk.props at the buildMultiTargeting root#16412Jakub Jareš (nohwnd) wants to merge 1 commit into
Jakub Jareš (nohwnd) wants to merge 1 commit into
Conversation
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>
Contributor
There was a problem hiding this comment.
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.propsatbuildMultiTargeting/folder root (and remove the ineffectivebuildMultiTargeting/<tfm>/copies). - Stop shipping the unsupported-TFM shim
.targetsunderbuildMultiTargeting/(to avoid unconditional outer-build failures). - Strengthen
eng/verify-nupkgs.ps1to validate package layout (not just file counts), specifically enforcing correctbuildMultiTargetingplacement 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
buildMultiTargeting/<PackageId>.propsis what NuGet imports into the outer build of a multi-targeting project. The outer build has noTargetFramework, so it cannot resolve a TFM subfolder. We shipped the props only asbuildMultiTargeting/net8.0/,net462/,netcoreapp2.0/andnetstandard2.0/, and nothing at the root, so the outer build imported nothing at all.TestProject,IsTestProjectand theTestContainercapability were never set there. Pack readsIsPackableon 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.targetsthere at all.The props now goes to the
buildMultiTargetingroot and the four TFM subfolder copies are gone. I removed them rather than leaving them, because a dead copy of the unsupported-TFM shim underbuildMultiTargeting/netstandard2.0/reads like it can fire on an outer build, and it cannot.build/<tfm>/is untouched. No.targetsgoes to the root:Microsoft.NET.Test.Sdk.targetsis the unsupported-TFM shim and itsInitialTargetserror has noTargetFrameworkcondition, so it would fail every outer build.verify-nupkgs.ps1only 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 thebuildMultiTargetingroot, 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 packtruetruefalseSame result for
<Project Sdk="MSTest.Sdk/4.0.1">withUseVSTest, which is the shape from the issue, and on both the 9.0.317 and 10.0.303 SDKs.Microsoft.NET.Test.Sdkgoes from 26 files to 21;eng/expected-nupkg-file-counts.jsonis regenerated from a clean Release pack build. Reverting the csproj and re-runningverify-nupkgs.ps1fails with exit code 1.Fix #15309
🤖