Setting up NuGet
-
Create the following environment variables depending on the authentication method:
IAM tokenAPI key-
Get an IAM token for the Yandex account or service account you are going to use for authentication.
-
Create the
REGISTRY_USERNAMEandREGISTRY_PASSWORDenvironment variables:export REGISTRY_USERNAME="iam" export REGISTRY_PASSWORD="<IAM_token>"Where:
REGISTRY_USERNAME: Authentication method.REGISTRY_PASSWORD: Body of the previously obtained IAM token.
Note
The IAM token's lifetime is limited to 12 hours.
-
Create an API key for the service account you are going to use for authentication.
When creating a key, specify its scope:
yc.cloud-registry.artifacts.pull: To pull artifacts from the registry.yc.cloud-registry.artifacts.push: To push artifacts to the registry.
-
Create the
REGISTRY_USERNAMEandREGISTRY_PASSWORDenvironment variables:export REGISTRY_USERNAME="api_key" export REGISTRY_PASSWORD="<API_key>"Where:
REGISTRY_USERNAME: Authentication method.REGISTRY_PASSWORD: Body of the previously created API key.
Note
The API key maximum lifetime is set manually when you create the key.
-
-
Set up the NuGet configuration file:
dotnet CLINuGet CLIManuallyTo edit the NuGet configuration file using the dotnet CLI
, run this command:dotnet nuget add source "https://registry.yandexcloud.net/nuget/v3/<registry_ID>/index.json" \ -n "cloud-registry" \ -u %REGISTRY_USERNAME% \ -p %REGISTRY_PASSWORD% \ --store-password-in-clear-text --protocol-version 3To edit the NuGet configuration file using the NuGet CLI
, run thenuget.exefile with the following parameters:nuget sources add -Name "cloud-registry" \ -Source "https://registry.yandexcloud.net/nuget/v3/<registry_ID>/index.json" \ -Username "%REGISTRY_USERNAME%" \ -Password "%REGISTRY_PASSWORD%" \ -StorePasswordInClearText -ProtocolVersion 3-
Open the NuGet configuration file
:Note
When using the dotnet CLI, the configuration file is located at
~/.nuget/NuGet/NuGet.Config, while for the NuGet CLI, at~/.config/NuGet/NuGet.Config. -
Update the configuration in the file as follows:
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="cloud-registry" value="https://registry.yandexcloud.net/nuget/v3/<registry_ID>/index.json" protocolVersion="3" /> </packageSources> <packageSourceCredentials> <cloud-registry> <add key="Username" value="%REGISTRY_USERNAME%" /> <add key="ClearTextPassword" value="%REGISTRY_PASSWORD%" /> </cloud-registry> </packageSourceCredentials> </configuration>
-
Scope is an API key parameter that restricts the key's use to specific operations in addition to the service account's access permissions. For details, see API keys with scope and validity limits.