DotNetCoreRestoreSettings doesn't support keys? #3434
-
Hi! https://cakebuild.net/api/Cake.Common.Tools.DotNetCore/DotNetCoreAliases/6E238F91 doesn't mention any API keys. I browsed around and found https://cakebuild.net/api/Cake.Common.Tools.NuGet.Restore/NuGetRestoreSettings/ , that seems to be old/deprecated/duplicate? Also found https://stackoverflow.com/a/38818942 which as a workaround manipulates nuget sources, but that's from 2016... Many thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Option 1: dotnet nuget add sourcedotnet nuget add source <nuget server> --name <name> --username xxx --password xxx --store-password-in-clear-text If you wanted to call Option 2: nuget.configThe other route is creating a <?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="your-custom-feed" value="https://..." protocolVersion="3" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSourceCredentials>
<your-custom-feed>
<add key="Username" value="xxx" />
<add key="ClearTextPassword" value="xxx" />
</your-custom-feed>
</packageSourceCredentials>
</configuration>
|
Beta Was this translation helpful? Give feedback.
-
The underlying SDK CLI dotnet restore command doesn't support specifying an API key It can use either interactive or key present per source in implicit/specified nuget config file. The dotnet nuget command can be used here i.e. dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/OWNER/index.json" This is available in Cake using the DotNetCoreNuGetUpdateSource alias, example: var settings = new DotNetCoreNuGetSourceSettings
{
Source = "https://www.example.com/nugetfeed",
UserName = "username",
Password = "password",
StorePasswordInClearText = true
};
DotNetCoreNuGetUpdateSource("example", settings); https://cakebuild.net/api/Cake.Common.Tools.DotNetCore/DotNetCoreAliases/F55178ED If you're using github actions you can add token as a secret environment variable something like steps:
- name: Run Cake Script
run: dotnet cake
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} And you can then access token as environment variable |
Beta Was this translation helpful? Give feedback.
-
Ah yeah, every few months I trip on this and then forget that this is the underlying cause. |
Beta Was this translation helpful? Give feedback.
DotNetCoreRestore
is simply a wrapper arounddotnet restore
that comes with the .NET SDK.dotnet restore
does not support API keys directly. It relies on the existing NuGet sources that you set up previously on the machine (e.g. viadotnet nuget
) and/or through anuget.config
file you can add to your repo with your nuget sources.Option 1: dotnet nuget add source
If you wanted to call
dotnet nuget
via Cake, you can call viaDotNetCoreNuGetAddSource
and can useDotNetCoreNuGetHasSource
to check if a source already exists before trying to create it. All thedotnet nuget
Cake wra…