Skip to content

fix: make NuGetizer self-pack robust so build/ assets always land correctly#726

Merged
kzu merged 1 commit into
mainfrom
fix/robust-nugetizer-self-pack
Jun 24, 2026
Merged

fix: make NuGetizer self-pack robust so build/ assets always land correctly#726
kzu merged 1 commit into
mainfrom
fix/robust-nugetizer-self-pack

Conversation

@kzu

@kzu kzu commented Jun 24, 2026

Copy link
Copy Markdown
Member

Problem

NuGetizer 1.4.8 (and builds after the PackageId / duplicate-import sync work) was publishing a broken package: its own build/*.props, build/*.targets, NuGetizer.*, etc. ended up under content/ + contentFiles/any/... instead of build/ (and buildMultiTargeting/).

This broke downstream users because the MSBuild targets/props were not discovered.

Root cause

  • "dotnet pack" (and GeneratePackageOnBuild=true) skipped the old delegation condition.
  • The forced import of the real NuGet.Build.Tasks.Pack.targets (added to workaround SDK PackageId defaults) made the SDK pack path win for NuGetizer.Tasks.
  • No explicit location metadata + inference falling back to DefaultPackFolder=content for None/Content items.

Fix (robust)

  • Add explicit PackagePath="build\..." (with overrides for the buildMultiTargeting copies) on all the build support files. PackagePath is honored by both NuGetizer and the SDK pack.
  • Add a late Pack target delegator in Directory.targets (after the SDK pack import) that forces the NuGetize=true path for PackFolder=build projects.
  • Condition the manual real-pack-targets import on NuGetize != 'true'.
  • Loosen the small delegation conditions so it is no longer tied to GeneratePackageOnBuild=='false'.

These changes make the layout of NuGetizer's own assets independent of how dotnet pack / IDE pack / Directory.Build changes are made in the future.

Fixes the 1.4.8 layout regression reported for the published package.

…build/ not content/

The v1.4.8 regression (triggered by syncs for PackageId defaults + the
duplicate NuGet pack import workaround) caused the project's *.props,
*.targets and related build assets to end up under content/ and
contentFiles/ in the published .nupkg instead of build/.

Root cause:
- 'dotnet pack' sets GeneratePackageOnBuild=true, which skipped the
  old delegation condition in NuGetizer.Tasks.Pack.targets.
- The forced <Import> of real NuGet.Build.Tasks.Pack.targets (late in
  Directory.Build.targets) made the SDK pack path win.
- Without explicit location metadata, inference + SDK defaults treated
  the files as content.

Robust fix:
* Explicit PackagePath="build\..." (and buildMultiTargeting for the
  special ones) on the build support files. PackagePath takes precedence
  in both NuGetizer's AssignPackagePath and the SDK pack.
* Late <Target Name="Pack"> delegator in Directory.targets (after the
  SDK pack import) so PackFolder=build projects (including NuGetizer
  itself) force the NuGetize=true path.
* Condition the manual pack targets import on 'NuGetize' != 'true'.
* Loosen the small Pack delegator conditions so the delegation is not
  tied to GeneratePackageOnBuild=='false'.

This ensures correct layout even if the pack driver or Directory.Build
changes again.
@kzu kzu added the bug Something isn't working label Jun 24, 2026
@kzu

kzu commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

246 passed 246 passed 69 skipped
246 passed 246 passed 69 skipped

🧪 Details on Ubuntu 24.04.4 LTS
🧪 Details on Microsoft Windows 10.0.26100

from dotnet-retest v1.0.0 on .NET 10.0.9 with 💜 by @devlooped

@kzu kzu enabled auto-merge (rebase) June 24, 2026 23:52
kzu added a commit to devlooped/oss that referenced this pull request Jun 24, 2026
…jects (#39)

### Problem
Projects using NuGetizer + `PackFolder=build` (the standard way to
author MSBuild/ tool packages) would get their assets incorrectly placed
under `content/` + `contentFiles/` when packed via `dotnet pack`.

This is the same root cause that affected the nugetizer 1.4.8 release.

### Root cause
- The shared `Directory.Build.targets` always imported the real
`NuGet.Build.Tasks.Pack.targets`.
- "dotnet pack" flows did not reliably go through the `NuGetize=true`
path.
- Result: SDK pack defaults won instead of NuGetizer's `PackFolder`
inference.

### Fix
* Condition the import of the real pack targets: `And '$(NuGetize)' !=
'true'`. When a project opts into NuGetizer via `NuGetize`, don't pull
in the conflicting SDK pack targets.
* Add a late `<Target Name="Pack">` delegator (after the pack import)
that, for any project with `PackFolder=build` or `buildTransitive`,
re-invokes MSBuild with `NuGetize=true`. This guarantees the correct
packaging logic runs.

The delegator is declared late in the file so it takes precedence.

See also the consuming change in
devlooped/nugetizer#726
@kzu kzu merged commit 1894e2f into main Jun 24, 2026
4 checks passed
@kzu kzu deleted the fix/robust-nugetizer-self-pack branch June 24, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant