spectreconsole/spectre.console · error · CakeException
No NuGet API key was provided.
Error message
No NuGet API key was provided.
What it means
Thrown by the Cake 'Publish-NuGet' build task when the 'nuget-key' argument is missing or blank. The task reads Argument<string?>("nuget-key", null) and throws CakeException before attempting any push, so the build aborts deterministically rather than failing mid-publish.
Source
Thrown at build.cs:84
Verbosity = DotNetVerbosity.Minimal,
NoLogo = true,
NoRestore = true,
NoBuild = true,
OutputDirectory = "./.artifacts",
MSBuildSettings = new DotNetMSBuildSettings()
.TreatAllWarningsAs(MSBuildTreatAllWarningsAs.Error)
});
});
Task("Publish-NuGet")
.WithCriteria(ctx => BuildSystem.IsRunningOnGitHubActions, "Not running on GitHub Actions")
.IsDependentOn("Package")
.Does(ctx =>
{
var apiKey = Argument<string?>("nuget-key", null);
if (string.IsNullOrWhiteSpace(apiKey))
{
throw new CakeException("No NuGet API key was provided.");
}
foreach (var file in ctx.GetFiles("./.artifacts/*.nupkg"))
{
ctx.Information("Publishing {0}...", file.GetFilename().FullPath);
DotNetNuGetPush(file.FullPath, new DotNetNuGetPushSettings
{
Source = "https://api.nuget.org/v3/index.json",
ApiKey = apiKey,
});
}
});
////////////////////////////////////////////////////////////////
// Targets
Task("Publish")
.IsDependentOn("Publish-NuGet");View on GitHub (pinned to 0acc92fada)
Solutions
- Pass the key explicitly: `dotnet cake --target=Publish-NuGet --nuget-key=YOUR_KEY`
- In GitHub Actions, expose the secret as a step env/argument, e.g. `--nuget-key=${{ secrets.NUGET_API_KEY }}`, and verify the secret name matches
- If you do not intend to publish, run a different target (e.g. Package) instead of Publish-NuGet
- Add a CI guard that fails fast with a clearer message when the secret is unset
Example fix
// before
var apiKey = Argument<string?>("nuget-key", null);
if (string.IsNullOrWhiteSpace(apiKey))
{
throw new CakeException("No NuGet API key was provided.");
}
// after (helpful guidance in the message)
var apiKey = Argument<string?>("nuget-key", null);
if (string.IsNullOrWhiteSpace(apiKey))
{
throw new CakeException(
"No NuGet API key was provided. Pass --nuget-key=VALUE or set the NUGET_API_KEY secret in CI.");
} Defensive patterns
Strategy: validation
Validate before calling
// In the build script or a pre-check step, fail with guidance before the task runs:
var apiKey = Argument<string?>("nuget-key", null);
if (string.IsNullOrWhiteSpace(apiKey))
{
Information("Set --nuget-key=VALUE or the NUGET_API_KEY secret to publish.");
return; // or skip the Publish-NuGet target via criteria Prevention
- Store the NuGet key as a GitHub Actions secret and map it explicitly to the --nuget-key argument
- Document the required argument in the build script header
- Run Publish-NuGet only in release workflows, not on every push
When it happens
Trigger: Invoking the Publish-NuGet target (directly or via its dependents) without passing --nuget-key=VALUE on the command line and without the NUGET_KEY/nuget-key variable set in the CI environment. The task is also gated by WithCriteria(IsRunningOnGitHubActions), so it only runs inside GitHub Actions.
Common situations: Running `dotnet cake --target=Publish-NuGet` locally without credentials; a GitHub Actions workflow that forgot to map a secret into the `nuget-key` argument; the secret name was renamed so the variable resolves empty.
Related errors
- Failed to read colors.json at {file.Path}
- Failed to read emoji.json at {file.Path}
- Failed to read spinners_default.json at {file.Path}
- Failed to read spinners_sindresorhus.json at {file.Path}
AI-assisted analysis of spectreconsole/spectre.console@0acc92fada (2026-08-13).
Data as JSON: /api/errors/2531c690f9bac206.
Report an issue: GitHub.