Skip to content

Conversation

@BYK
Copy link
Member

@BYK BYK commented Dec 29, 2025

Summary

Add workspaces support to the NuGet target, enabling automatic discovery of .NET packages from solution files, topological sorting based on project dependencies, and sequential publishing in the correct order.

Closes #649

Changes

  • New utility module (src/utils/dotnetWorkspaces.ts):

    • Parse .sln files using regex (static text parsing)
    • Parse .csproj files using XML parser to extract package info and dependencies
    • Topologically sort packages so dependencies are published before dependents
  • NuGet target enhancements (src/targets/nuget.ts):

    • Add static expand() method for workspace expansion
    • Add config options: workspaces, solutionPath, includeWorkspaces, excludeWorkspaces, artifactTemplate
    • Remove --skip-duplicate flag (no longer needed with proper ordering)
    • Change from Promise.all to forEachChained for sequential publishing
  • Security: All discovery uses static file parsing only - no code execution from target repo

  • Tests: 29 new unit tests for the utility and target expansion

  • Documentation: Updated nuget.md with workspace configuration options and examples

Example Configuration

targets:
  - name: nuget
    workspaces: true
    solutionPath: src/Sentry.sln
    includeWorkspaces: '/^Sentry\./'
    excludeWorkspaces: '/\.Tests$/'

- 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
Copy link
Contributor

github-actions bot commented Dec 29, 2025

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
Copy link
Contributor

github-actions bot commented Dec 29, 2025

PR Preview Action v1.8.0

🚀 View preview at
https://getsentry.github.io/craft/pr-preview/pr-686/

Built to branch gh-pages at 2025-12-30 18:53 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

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
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
Copy link
Member Author

BYK commented Dec 30, 2025

@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 :)

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

3 participants