{"record":{"id":"1b4832c2a68285ca","repo":"ElectronNET/Electron.NET","slug":"could-not-resolve-the-nuget-api-key","errorCode":null,"errorMessage":"Could not resolve the NuGet API key.","messagePattern":"Could not resolve the NuGet API key\\.","errorType":"exception","errorClass":"BuildAbortedException","httpStatus":null,"severity":"error","filePath":"nuke/Build.cs","lineNumber":156,"sourceCode":"\n            DotNetTest(s => s\n                .SetProjectFile(TestProject)\n                .SetConfiguration(Configuration)\n                .When(_ => GitHubActions.Instance is not null, x => x.SetLoggers(\"GitHubActions\"))\n            );\n        });\n\n    Target PublishPackages => _ => _\n        .DependsOn(Compile)\n        .DependsOn(RunUnitTests)\n        .Executes(() =>\n        {\n            var apiKey = Environment.GetEnvironmentVariable(\"NUGET_API_KEY\");\n\n\n            if (apiKey.IsNullOrEmpty())\n            {\n                throw new BuildAbortedException(\"Could not resolve the NuGet API key.\");\n            }\n\n            foreach (var nupkg in ResultDirectory.GlobFiles(\"*.nupkg\"))\n            {\n                DotNetNuGetPush(s => s\n                    .SetTargetPath(nupkg)\n                    .SetSource(\"https://api.nuget.org/v3/index.json\")\n                    .SetApiKey(apiKey));\n            }\n        });\n\n    Target PublishPreRelease => _ => _\n        .DependsOn(PublishPackages)\n        .Executes(() =>\n        {\n            string gitHubToken;\n\n            if (GitHubActions != null)","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/ElectronNET/Electron.NET/blob/87cc6f98b6a9c5968d7846c0e775ea713bd0d7b2/nuke/Build.cs#L138-L174","documentation":"The build's NuGet push step requires a NuGet.org API key to authenticate the `dotnet nuget push` of the generated .nupkg packages. Before pushing, it reads the NUGET_API_KEY environment variable; if it is missing or empty, the build aborts with a BuildAbortedException so no unauthenticated push is attempted. This is a deliberate fail-fast guard in the CI publish pipeline.","triggerScenarios":"Running the Nuke Push/Publish target (Build.cs:156) when the NUGET_API_KEY environment variable is unset or an empty string at the moment ResultDirectory.GlobFiles(\"*.nupkg\") packages are about to be pushed.","commonSituations":"CI pipeline secrets not configured (e.g. GitHub Actions workflow lacks NUGET_API_KEY in env/secrets); running the publish target locally where the key was never exported; secret renamed in the CI provider so the env var name no longer matches; shell profile exporting an empty NUGET_API_KEY.","solutions":["Set the NUGET_API_KEY environment variable before running the build (e.g. export NUGET_API_KEY=... locally, or add it as a secret/env in the CI workflow).","In GitHub Actions, map the repository secret to the env var: env: NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}.","Verify the secret name in the CI provider exactly matches NUGET_API_KEY (case-sensitive) and is scoped to the branch/organization running the build.","If you don't intend to publish, run a target that does not include the NuGet push step."],"exampleFix":"// before (GitHub Actions)\n- run: ./build.sh Publish\n// after\n- run: ./build.sh Publish\n  env:\n    NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(\"NUGET_API_KEY\")))\n    throw new InvalidOperationException(\"Set NUGET_API_KEY before running the publish target.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    // run publish target\n}\ncatch (BuildAbortedException ex) when (ex.Message.Contains(\"NuGet API key\"))\n{\n    Logger.Error(\"NUGET_API_KEY is not set; skipping publish.\");\n}","preventionTips":["Store NUGET_API_KEY as a CI secret and map it to the env var in the workflow.","Add a pre-build sanity check that fails early with a clear message.","Document required env vars in the repo README/build help.","Never hardcode the key; always read from the environment."],"tags":["nuget","publish","ci","environment-variable","build"],"backgroundTag":"missing-env-var","analyzedSha":"87cc6f98b6a9c5968d7846c0e775ea713bd0d7b2","analyzedAt":"2026-09-14T03:09:47.608Z","contentChangedAt":"2026-09-14T03:09:47.608Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}