NuGet
Uploads packages to NuGet via .NET Core.
Configuration
Section titled “Configuration”| Option | Type | Description |
|---|---|---|
workspaces |
boolean |
Enable workspace discovery to auto-generate targets for all packages in the solution |
solutionPath |
string |
Path to the solution file (.slnx or .sln) relative to repo root. Auto-discovers if not specified, preferring .slnx |
includeWorkspaces |
string |
Regex pattern to filter which packages to include. Example: '/^Sentry\./' |
excludeWorkspaces |
string |
Regex pattern to filter which packages to exclude. Example: '/\.Tests$/' |
serverUrl |
string |
NuGet server URL. Default: https://api.nuget.org/v3/index.json |
Workspace Support
Section titled “Workspace Support”When workspaces: true is enabled, Craft will automatically:
- Parse the solution file (
.slnxor.sln) to discover all projects, including projects nested in solution folders - Parse each
.csprojfile to extract package IDs and dependencies - Skip projects that are not packable (
<IsPackable>false</IsPackable>) - Sort packages topologically so dependencies are published before dependents
- Expand the single nuget target into multiple individual targets (one per package)
- Publish packages sequentially in the correct order
Each package’s .snupkg symbol package, if present, is pushed together with its .nupkg.
This is useful for monorepos with multiple NuGet packages that depend on each other.
If workspaces: true is set but discovery finds no packages, or the filters exclude all of them, Craft fails with a configuration error instead of skipping the target.
Retrying a Partial Publish
Section titled “Retrying a Partial Publish”Craft does not pass --skip-duplicate to dotnet nuget push: pushing a version that already exists fails, because Craft can’t otherwise tell whether the existing package is the one it’s trying to publish.
Instead, before pushing each .nupkg, Craft checks whether the server already has that version:
- Not published: the
.nupkgis pushed, anddotnet nuget pushpushes the.snupkgnext to it right after. - Published with identical contents: the
.nupkgis not pushed again. Craft downloads the published package from the feed’sPackageBaseAddressand compares every file in it with the local package, ignoring.signature.p7s(the repository signature the server adds). If there is a.snupkgand the server doesn’t have it yet, only the.snupkgis pushed. - Published with different contents: the target fails. NuGet versions are immutable, so publish a new version instead.
This lets you retry a release that failed halfway, for example when the .nupkg was uploaded but its .snupkg wasn’t, by rerunning the target, instead of someone pushing the missing file by hand.
Environment Variables
Section titled “Environment Variables”| Name | Description |
|---|---|
NUGET_API_TOKEN |
NuGet API token |
NUGET_DOTNET_BIN |
Path to .NET Core. Default: dotnet |
Examples
Section titled “Examples”Basic Usage
Section titled “Basic Usage”Publishes all .nupkg artifacts found:
targets: - name: nugetWorkspace Discovery
Section titled “Workspace Discovery”Automatically discovers and publishes all packages from a solution file in dependency order:
targets: - name: nuget workspaces: trueWorkspace with Filtering
Section titled “Workspace with Filtering”Publish only packages matching a pattern, excluding packable test apps:
targets: - name: nuget workspaces: true solutionPath: Sentry.slnx includeWorkspaces: '/^Sentry/' excludeWorkspaces: '/(TrimTest|CrashableApp)$/'