Skip to content

feat(nuget)!: Add workspaces support for dependency-ordered publishing - #686

Merged
BYK merged 11 commits into
masterfrom
feat/nuget-workspaces
Oct 21, 2026
Merged

BYK merged 11 commits into
masterfrom
feat/nuget-workspaces

Conversation

@BYK

@BYK BYK commented Dec 29, 2025 •

Copy link
Copy Markdown
Member

Adds workspaces: true to the NuGet target. Craft discovers the .NET packages in a solution, sorts them by their project dependencies, and expands the single nuget target into one target per package, published in dependency order.

Closes #649

Breaking change

The nuget target no longer passes --skip-duplicate to dotnet nuget push, including the default non-workspace path. Craft no longer skips an existing version blindly. Before each push it checks what the feed already has, so a retry only skips packages it has verified are identical, and fails on anything else:

  • Version not published: push the .nupkg; dotnet nuget push sends the .snupkg next to it right after.
  • Published and identical: don't push the .nupkg again. Craft downloads the published copy from the feed's PackageBaseAddress (flat container) and compares the SHA-256 of every file with the local package. It ignores .signature.p7s, which nuget.org adds when it repository-signs the package. If there's a local .snupkg and nuget.org's symbol CDN (globalcdn.nuget.org/symbol-packages/…) doesn't have it, only the .snupkg is pushed.
  • Published but different: fail the target. The version is taken, so publish a new one.
  • State unknown (service index unreachable, auth required, unexpected HTTP status): push the .nupkg as before, so an existing version still fails the push.

To recover from a partial publish, rerun the target. For example, if a .nupkg was uploaded but its .snupkg wasn't, the rerun uploads just the symbols, with no manual nuget push. Limits:

  • Symbol packages can only be checked on nuget.org. On other feeds the .snupkg is pushed again and the server decides whether to accept it.
  • nuget.org only serves a package once it has been validated, which usually takes a few minutes. A retry right after an upload can still get a 409, and the error says to wait and retry.

With workspaces enabled, each package is its own target in the publish state, so a rerun only retries the packages that failed. Projects that publish many packages through a plain - name: nuget target should switch to workspaces: true.

workspaces: true on the npm target now also fails with a configuration error when no publishable packages are found, instead of warning and skipping the target.

How discovery works

Discovery only parses files statically. It never runs MSBuild or any code from the target repo.

  • Reads .slnx (preferred) or .sln, including projects nested in .slnx <Folder> elements.
  • Reads PackageId and IsPackable from each .csproj and from the nearest Directory.Build.props, following imports with static paths. Values with a Condition or a $(...) reference are ignored, and IsPackable defaults to true.
  • Collects ProjectReference dependencies from the project and from statically imported .props/.targets files, regardless of conditions. Platform-specific dependencies, such as Sentry's Android and Cocoa bindings, are still published first.
  • Fails with a configuration error if no packable projects are found, or if includeWorkspaces/excludeWorkspaces remove all of them.

Against sentry-dotnet's Sentry.slnx, the config below expands to exactly the packages it ships, in a valid order.

Other changes

  • Each expanded target matches its package's .nupkg and .snupkg. publish splits artifacts by extension, so a .snupkg is pushed together with its .nupkg, or on its own only when that .nupkg is already published with identical contents.
  • escapeRegex is now shared by the npm, NuGet and PowerShell artifact patterns, and it escapes all regex special characters.

Example

targets:
  - name: nuget
    workspaces: true
    solutionPath: Sentry.slnx
    includeWorkspaces: '/^Sentry/'
    excludeWorkspaces: '/(TrimTest|CrashableApp)$/'

Run craft targets after changing the solution or the filters to check the expanded list. A package that discovery skips is simply not published.

via byk.

--

View Junior Session [Sentry]

- Add automatic discovery of NuGet packages from .sln/.csproj files
- Topologically sort packages by dependencies for correct publish order
- Change from parallel (Promise.all) to sequential publishing
- Remove --skip-duplicate flag (no longer needed with proper ordering)
- Add workspace config options: workspaces, solutionPath, includeWorkspaces,
  excludeWorkspaces, artifactTemplate
- Security: All discovery uses static file parsing only (no code execution)

Closes #649
@github-actions

github-actions Bot commented Dec 29, 2025 •

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (nuget) Add workspaces support for sequential publishing by BYK in #686

Bug Fixes 🐛

  • (changelog) Disable author mentions in PR preview comments by BYK in #684
  • (github) Clean up orphaned draft releases on publish failure by BYK in #681
  • (publish) Fail early on dirty git repository by BYK in #683

🤖 This preview updates automatically when you update the PR.

@github-actions

github-actions Bot commented Dec 29, 2025 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-10-21 14:12 UTC

Comment thread src/utils/dotnetWorkspaces.ts Fixed
BYK added 2 commits December 29, 2025 21:49
…tPattern

Refactor escapeRegex helper to top-level function and use it in
packageIdToNugetArtifactPattern to properly escape all regex meta-characters,
not just dots.
…pattern

- Export escapeRegex from workspaces.ts for reuse
- Fix packageNameToArtifactPattern to escape all regex special chars
- Use shared escapeRegex in dotnetWorkspaces.ts and powershell.ts
BYK added 3 commits December 30, 2025 00:03
Instead of fully sequential publishing, use p-limit to allow up to 3
concurrent package uploads. This provides a good balance between speed
and avoiding overwhelming NuGet.org.
@bruno-garcia

Copy link
Copy Markdown
Member

hey @BYK , thanks for looking at improving the nuget upload experience. Uploading things in order is probably an improvement (though processing the packages happen async so not sure nuget.org will actually process them in order too)

Did you try this out with our SDK? Some things worth noting:

Our SDK doesn't only rely on .sln and .csproj, unfortunately things are more complicated in .NET. There's some Directory.Build.props or .targets that get included in the build by the .NET SDK itself (you won't find necessarily Include="../file.props" for example, inside .csproj files). So you might not be finding everything you'd like to.
Or maybe it will since at least anything that generates .nupkg (NuGet packages) should have at least 1 .csproj. but worth testing it out.

Wrt parsing .sln, note that there's a .slnx file now and we plan (should at least) to migrate over to it eventually once tooling is more mature around it.

One other thing is that we have solution filters in the repo, which we use to develop different parts (Mobile vs Web etc) but I don't think this will affect craft or your PR. But worth mentioning for context.

Lastly and this might affect this PR is that we output not only nupkg but also snupkg files, which contain the debug symbols. But if at the end of the day it's judt running dotnet nuget publish or whatever the command is it should be fine since it should upload both if they are in the target directory

Hope this context helps. Lets hear from @Flash0ver who is the maintainer of .NET he might have other/more context here.

- Artifact patterns now match both .nupkg and .snupkg (symbol packages)
- Add .slnx (XML-based solution) file format support
- Add explicit tests for escapeRegex backslash handling
- Prefer .slnx over .sln when both exist
@BYK

BYK commented Dec 30, 2025

Copy link
Copy Markdown
Member Author

@bruno-garcia thanks a lot for the great feedback! I'm just vibe coding this to get the ball rolling. Fed your feedback to Cursor and it did some more things: f0be729

I'll wait for @Flash0ver's review and tests on the SDK repo as this is being done mostly for our own SDK :)

@bruno-garcia
bruno-garcia removed their request for review January 19, 2026 14:25
@jamescrosswell

Copy link
Copy Markdown
Contributor

Wrt parsing .sln, note that there's a .slnx file now and we plan (should at least) to migrate over to it eventually once tooling is more mature around it.

We have moved over to slnx now - it's a way simpler format than the old sln files so hopefully that makes things easier.

sentry-junior Bot and others added 2 commits October 19, 2026 10:51
# Conflicts:
#	package.json
#	src/targets/nuget.ts
#	src/targets/powershell.ts
#	yarn.lock

Co-Authored-By: Burak Yigit Kaya <[email protected]>
…iscovery

- Find projects nested in slnx <Folder> elements (Sentry.slnx layout)
- Inherit IsPackable/PackageId from Directory.Build.props and its static imports
- Ignore conditional or property-dependent MSBuild values
- Collect ProjectReference deps from imported .props/.targets regardless of
  conditions, and map project names to PackageIds
- Never push .snupkg files on their own when includeNames matches both

Co-Authored-By: Burak Yigit Kaya <[email protected]>

@ric-oliv ric-oliv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking this up!

I tested the discovery against the current sentry-dotnet repo (Sentry.slnx, 98 projects). With the filters from the docs example, it expands to exactly the 23 packages we ship, in a sensible order.

What blocks this for me is that the PR also changes the default (non-workspace) path. sentry-dotnet uses that path today with a plain - name: nuget. getsentry/publish runs getsentry/craft:latest, so these changes would hit our next release without any config change:

  • --skip-duplicate is removed, so retrying a partially failed publish fails on the first package that's already on nuget.org (409)

Before merging, I'd like to see:

  1. Keep --skip-duplicate.
  2. Drop the pLimit change from this PR, unless we hit rate limiting on NuGet.org.
  3. Fail instead of warning when workspaces: true finds no packages.
  4. Remove artifactTemplate from the nuget target.
  5. Update the PR description. It still says forEachChained, and the example uses src/Sentry.sln.

Comment thread src/targets/nuget.ts Resolved
Comment thread src/targets/nuget.ts Resolved
Comment thread src/targets/nuget.ts Resolved
Comment thread src/targets/nuget.ts Resolved
Comment thread docs/src/content/docs/targets/nuget.md Resolved
- Drop the p-limit upload concurrency; keep master's Promise.all
- Throw ConfigurationError when workspace discovery (nuget and npm)
  finds no packages or filters remove all of them
- Remove nuget artifactTemplate: it couldn't match path-style names
  and silently dropped .snupkg files
- Document that skipped packages aren't published and to check
  `craft targets`

Co-Authored-By: byk <[email protected]>
@sentry-junior sentry-junior Bot changed the title feat(nuget): Add workspaces support for sequential publishing feat(nuget)!: Add workspaces support for dependency-ordered publishing Oct 19, 2026
Before pushing a .nupkg, check whether the version is already on the
feed. If it is, download the published package and compare every file
(SHA-256, ignoring the .signature.p7s the server adds). Identical
packages are not pushed again; only a missing .snupkg is pushed, which
is checked on nuget.org's symbol CDN. A different package under the
same version fails the target. If the state can't be determined, the
.nupkg is pushed as before so a duplicate still fails loudly.

Co-Authored-By: Burak Yigit Kaya <[email protected]>
@BYK
BYK marked this pull request as ready for review October 20, 2026 15:45
@BYK
BYK requested a review from ric-oliv October 20, 2026 15:45

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cf6df6f. Configure here.

Comment thread src/utils/nugetRegistry.ts Resolved

@ric-oliv ric-oliv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding the recovery! I tested it against sentry-dotnet. craft targets still expands our config to exactly the packages we ship, and the new check returns identical against nuget.org for all 23 packages of 7.0.0-rc.2. So a retry would skip those and only push a .snupkg that's missing.

One thing before merging. The description's breaking-change section still says an existing version fails "because Craft can't verify that the existing package matches the one it's publishing". It can now. Could you update it to describe what a retry does, like the new "Retrying a Partial Publish" section in the docs? That way anyone reading about the breaking change also sees how to recover.

@BYK
BYK merged commit ab8b920 into master Oct 21, 2026
30 checks passed
@BYK
BYK deleted the feat/nuget-workspaces branch October 21, 2026 14:11
jamescrosswell pushed a commit to getsentry/sentry-dotnet that referenced this pull request Oct 21, 2026
Craft's nuget target is dropping --skip-duplicate (getsentry/craft#686). With our single nuget
target, a retry after a partly failed publish would stop at the first package that's already on
nuget.org. With workspaces enabled, craft splits the target into one target per package, in
dependency order, and a retry skips the packages that already went out.

Craft releases without workspace support pass the new keys through and keep publishing everything
as one target, so this is safe to merge before the craft release.

Co-authored-by: Claude Opus 5.5 <[email protected]>

This branch was previously deployed

1 inactive deployment
false — cf6df6f2 Deployed Oct 20, 2026 by sentry-junior[bot] via Build #3127
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.

Add workspaces support for dotnet/nuget

5 participants