nuget source Add -Name <source_name> -Source "https://gitlab.example.com/api/v4/projects/<your_project_id>/packages/nuget/index.json" -UserName <gitlab_username or deploy_token_username> -Password <gitlab_personal_access_token or deploy_token>
<source_name>
is the desired source name.For example:
nuget source Add -Name "GitLab" -Source "https://gitlab.example.com/api/v4/projects/10/packages/nuget/index.json" -UserName carol -Password 12345678asdf
Group-level endpoint
To install a NuGet package from a group, use a group-level endpoint.
To use the group-level NuGet endpoint, add the Package Registry as a source with nuget
:
nuget source Add -Name <source_name> -Source "https://gitlab.example.com/api/v4/groups/<your_group_id>/-/packages/nuget/index.json" -UserName <gitlab_username or deploy_token_username> -Password <gitlab_personal_access_token or deploy_token>
<source_name>
is the desired source name.For example:
nuget source Add -Name "GitLab" -Source "https://gitlab.example.com/api/v4/groups/23/-/packages/nuget/index.json" -UserName carol -Password 12345678asdf
Add a source with Visual Studio
A project-level endpoint is required to publish NuGet packages to the Package Registry.
A project-level endpoint is also required to install NuGet packages from a project.
To use the project-level NuGet endpoint, add the Package Registry as a source with Visual Studio:
- Open Visual Studio.
- In Windows, select Tools > Options. On macOS, select Visual Studio > Preferences.
- In the NuGet section, select Sources to view a list of all your NuGet sources.
- Select Add.
-
Complete the following fields:
Name: Name for the source.-
Source:
https://gitlab.example.com/api/v4/projects/<your_project_id>/packages/nuget/index.json
,
where <your_project_id>
is your project ID, and gitlab.example.com
is
your domain name.
- Select Save.
-
When you access the package, you must enter your Username and Password:
Username: Your GitLab username or deploy token username.-
Password: Your personal access token or deploy token.
The source is displayed in your list.
If you get a warning, ensure that the Source, Username, and
Password are correct.
Group-level endpoint
To install a package from a group, use a group-level endpoint.
To use the group-level NuGet endpoint, add the Package Registry as a source with Visual Studio:
- Open Visual Studio.
- In Windows, select Tools > Options. On macOS, select Visual Studio > Preferences.
- In the NuGet section, select Sources to view a list of all your NuGet sources.
- Select Add.
-
Complete the following fields:
Name: Name for the source.-
Source:
https://gitlab.example.com/api/v4/groups/<your_group_id>/-/packages/nuget/index.json
,
where <your_group_id>
is your group ID, and gitlab.example.com
is
your domain name.
- Select Save.
-
When you access the package, you must enter your Username and Password.
Username: Your GitLab username or deploy token username.-
Password: Your personal access token or deploy token.
The source is displayed in your list.
If you get a warning, ensure that the Source, Username, and
Password are correct.
Add a source with the .NET CLI
A project-level endpoint is required to publish NuGet packages to the Package Registry.
A project-level endpoint is also required to install NuGet packages from a project.
To use the project-level
NuGet endpoint, add the Package Registry as a source with nuget
:
dotnet nuget add source "https://gitlab.example.com/api/v4/projects/<your_project_id>/packages/nuget/index.json" --name <source_name> --username <gitlab_username or deploy_token_username> --password <gitlab_personal_access_token or deploy_token>
<source_name>
is the desired source name.
--store-password-in-clear-text
might be necessary depending on your operating system.For example:
dotnet nuget add source "https://gitlab.example.com/api/v4/projects/10/packages/nuget/index.json" --name gitlab --username carol --password 12345678asdf
Group-level endpoint
To install a NuGet package from a group, use a group-level endpoint.
To use the group-level
NuGet endpoint, add the Package Registry as a source with nuget
:
dotnet nuget add source "https://gitlab.example.com/api/v4/groups/<your_group_id>/-/packages/nuget/index.json" --name <source_name> --username <gitlab_username or deploy_token_username> --password <gitlab_personal_access_token or deploy_token>
<source_name>
is the desired source name.
--store-password-in-clear-text
might be necessary depending on your operating system.For example:
dotnet nuget add source "https://gitlab.example.com/api/v4/groups/23/-/packages/nuget/index.json" --name gitlab --username carol --password 12345678asdf
Add a source with a configuration file
A project-level endpoint is required to:
To use the project-level Package Registry as a source for .NET:
- In the root of your project, create a file named
nuget.config
. -
Add this content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="gitlab" value="https://gitlab.example.com/api/v4/projects/<your_project_id>/packages/nuget/index.json" />
</packageSources>
<packageSourceCredentials>
<gitlab>
<add key="Username" value="%GITLAB_PACKAGE_REGISTRY_USERNAME%" />
<add key="ClearTextPassword" value="%GITLAB_PACKAGE_REGISTRY_PASSWORD%" />
</gitlab>
</packageSourceCredentials>
</configuration>
Configure the necessary environment variables:
export GITLAB_PACKAGE_REGISTRY_USERNAME=<gitlab_username or deploy_token_username>
export GITLAB_PACKAGE_REGISTRY_PASSWORD=<gitlab_personal_access_token or deploy_token>
Group-level endpoint
To install a package from a group, use a group-level endpoint.
To use the group-level Package Registry as a source for .NET:
- In the root of your project, create a file named
nuget.config
. -
Add this content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="gitlab" value="https://gitlab.example.com/api/v4/groups/<your_group_id>/-/packages/nuget/index.json" />
</packageSources>
<packageSourceCredentials>
<gitlab>
<add key="Username" value="%GITLAB_PACKAGE_REGISTRY_USERNAME%" />
<add key="ClearTextPassword" value="%GITLAB_PACKAGE_REGISTRY_PASSWORD%" />
</gitlab>
</packageSourceCredentials>
</configuration>
Configure the necessary environment variables:
export GITLAB_PACKAGE_REGISTRY_USERNAME=<gitlab_username or deploy_token_username>
export GITLAB_PACKAGE_REGISTRY_PASSWORD=<gitlab_personal_access_token or deploy_token>
Publish a NuGet package
Prerequisite:
When publishing packages:
- The Package Registry on GitLab.com can store up to 5 GB of content.
This limit is configurable for self-managed GitLab instances.
- If you publish the same package with the same version multiple times, each
consecutive upload is saved as a separate file. When installing a package,
GitLab serves the most recent file.
- When publishing packages to GitLab, they aren’t displayed in the packages user
interface of your project immediately. It can take up to 10 minutes to process
a package.
Publish a package with the NuGet CLI
Prerequisites:
Publish a package by running this command:
nuget push <package_file> -Source <source_name>
<package_file>
is your package filename, ending in .nupkg
.
<source_name>
is the source name used during setup.Publish a package with the .NET CLI
Prerequisites:
Publish a package by running this command:
Install the latest version of a package by running this command:
Install the latest version of a package by running this command: