{"record":{"id":"2531c690f9bac206","repo":"spectreconsole/spectre.console","slug":"no-nuget-api-key-was-provided","errorCode":null,"errorMessage":"No NuGet API key was provided.","messagePattern":"No NuGet API key was provided\\.","errorType":"exception","errorClass":"CakeException","httpStatus":null,"severity":"error","filePath":"build.cs","lineNumber":84,"sourceCode":"        Verbosity = DotNetVerbosity.Minimal,\n        NoLogo = true,\n        NoRestore = true,\n        NoBuild = true,\n        OutputDirectory = \"./.artifacts\",\n        MSBuildSettings = new DotNetMSBuildSettings()\n            .TreatAllWarningsAs(MSBuildTreatAllWarningsAs.Error)\n    });\n});\n\nTask(\"Publish-NuGet\")\n    .WithCriteria(ctx => BuildSystem.IsRunningOnGitHubActions, \"Not running on GitHub Actions\")\n    .IsDependentOn(\"Package\")\n    .Does(ctx =>\n{\n    var apiKey = Argument<string?>(\"nuget-key\", null);\n    if (string.IsNullOrWhiteSpace(apiKey))\n    {\n        throw new CakeException(\"No NuGet API key was provided.\");\n    }\n\n    foreach (var file in ctx.GetFiles(\"./.artifacts/*.nupkg\"))\n    {\n        ctx.Information(\"Publishing {0}...\", file.GetFilename().FullPath);\n        DotNetNuGetPush(file.FullPath, new DotNetNuGetPushSettings\n        {\n            Source = \"https://api.nuget.org/v3/index.json\",\n            ApiKey = apiKey,\n        });\n    }\n});\n\n////////////////////////////////////////////////////////////////\n// Targets\n\nTask(\"Publish\")\n    .IsDependentOn(\"Publish-NuGet\");","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/build.cs#L66-L102","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nvar apiKey = Argument<string?>(\"nuget-key\", null);\nif (string.IsNullOrWhiteSpace(apiKey))\n{\n    throw new CakeException(\"No NuGet API key was provided.\");\n}\n\n// after (helpful guidance in the message)\nvar apiKey = Argument<string?>(\"nuget-key\", null);\nif (string.IsNullOrWhiteSpace(apiKey))\n{\n    throw new CakeException(\n        \"No NuGet API key was provided. Pass --nuget-key=VALUE or set the NUGET_API_KEY secret in CI.\");\n}","handlingStrategy":"validation","validationCode":"// In the build script or a pre-check step, fail with guidance before the task runs:\nvar apiKey = Argument<string?>(\"nuget-key\", null);\nif (string.IsNullOrWhiteSpace(apiKey))\n{\n    Information(\"Set --nuget-key=VALUE or the NUGET_API_KEY secret to publish.\");\n    return; // or skip the Publish-NuGet target via criteria","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["build","nuget","ci-cd","cake","secrets"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}