A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.gitlab.com/user/packages/nuget_repository/ below:

NuGet packages in the package registry

Publish NuGet packages in your project’s package registry. Then, install the packages whenever you need to use them as a dependency.

The package registry works with:

To learn about the specific API endpoints these clients use, see the NuGet API reference.

Learn how to install NuGet.

Authenticate to the package registry

You need an authentication token to access the GitLab package registry. Different tokens are available depending on what you’re trying to achieve. For more information, review the guidance on tokens.

Use the GitLab endpoint for NuGet packages

You can use either a project or group endpoint to interact with the GitLab package registry:

Some actions, like publishing a package, are only available on the project endpoint.

Because of how NuGet handles credentials, the package registry rejects anonymous requests to public groups.

Add the package registry as a source for NuGet packages

To publish and install packages to the package registry, you must add the package registry as a source for your packages.

Prerequisites:

With the project endpoint

To add the package registry as a source with NuGet CLI, run the following command:

nuget source Add -Name <source_name> -Source "https://gitlab.example.com/api/v4/projects/<project_id>/packages/nuget/index.json" -UserName <gitlab_username> -Password <personal_access_token>

Replace:

For example:

nuget source Add -Name "GitLab" -Source "https://gitlab.example.com/api/v4/projects/10/packages/nuget/index.json" -UserName carol -Password <your_access_token>

To add the package registry as a source with .NET CLI, run the following command:

dotnet nuget add source "https://gitlab.example.com/api/v4/projects/<project_id>/packages/nuget/index.json" --name <source_name> --username <gitlab_username> --password <personal_access_token>

Replace:

Depending on your operating system, you may need to append --store-password-in-clear-text to the command.

For example:

dotnet nuget add source "https://gitlab.example.com/api/v4/projects/10/packages/nuget/index.json" --name gitlab --username carol --password <your_access_token> --store-password-in-clear-text

You can add the package registry as a source feed with the Chocolatey CLI. If you use Chocolatey CLI v1.X, you can add only a NuGet v2 source feed.

To add the package registry as a source for Chocolatey, run the following command:

choco source add -n=<source_name> -s "'https://gitlab.example.com/api/v4/projects/<project_id>/packages/nuget/v2'" -u=<gitlab_username> -p=<personal_access_token>

Replace:

For example:

choco source add -n=gitlab -s "'https://gitlab.example.com/api/v4/projects/10/packages/nuget/v2'" -u=carol -p=<your_access_token>

To add the package registry as a source with Visual Studio:

  1. Open Visual Studio.

  2. In Windows, select Tools > Options. On macOS, select Visual Studio > Preferences.

  3. In the NuGet section, select Sources to view a list of all your NuGet sources.

  4. Select Add.

  5. Complete the following fields:

  6. Select Save.

  7. When you access the package, you must enter your Username and Password:

The source is displayed in your list.

If you get a warning, ensure that the Source, Username, and Password are correct.

To add the package registry as a source with a .NET configuration file:

  1. In the root of your project, create a file named nuget.config.

  2. Add the following configuration:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
     <packageSources>
         <clear />
         <add key="gitlab" value="https://gitlab.example.com/api/v4/projects/<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>
  3. Configure the necessary environment variables:

    export GITLAB_PACKAGE_REGISTRY_USERNAME=<gitlab_username>
    export GITLAB_PACKAGE_REGISTRY_PASSWORD=<personal_access_token>

The previous example commands add a source named gitlab. Subsequent example commands refer to the source name (gitlab), not the source URL.

With the group endpoint

To add the package registry as a source with NuGET CLI:

nuget source Add -Name <source_name> -Source "https://gitlab.example.com/api/v4/groups/<group_id>/-/packages/nuget/index.json" -UserName <gitlab_username> -Password <personal_access_token>

Replace:

For example:

nuget source Add -Name "GitLab" -Source "https://gitlab.example.com/api/v4/groups/23/-/packages/nuget/index.json" -UserName carol -Password <your_access_token>

To add the package registry as a source with .NET CLI:

dotnet nuget add source "https://gitlab.example.com/api/v4/groups/<group_id>/-/packages/nuget/index.json" --name <source_name> --username <gitlab_username> --password <personal_access_token>

Replace:

The --store-password-in-clear-text flag 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 <your_access_token> --store-password-in-clear-text

To add the package registry as a source with Visual Studio:

  1. Open Visual Studio.

  2. In Windows, select Tools > Options. On macOS, select Visual Studio > Preferences.

  3. In the NuGet section, select Sources to view a list of all your NuGet sources.

  4. Select Add.

  5. Complete the following fields:

  6. Select Save.

  7. When you access the package, you must enter your Username and Password.

The source is displayed in your list.

If you get a warning, ensure that the Source, Username, and Password are correct.

To add the package registry as a source with a .NET configuration file:

  1. In the root of your project, create a file named nuget.config.

  2. Add the following configuration:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
     <packageSources>
         <clear />
         <add key="gitlab" value="https://gitlab.example.com/api/v4/groups/<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>
  3. Configure the necessary environment variables:

    export GITLAB_PACKAGE_REGISTRY_USERNAME=<gitlab_username>
    export GITLAB_PACKAGE_REGISTRY_PASSWORD=<personal_access_token>

The previous example commands add a source named gitlab. Subsequent example commands refer to the source name (gitlab), not the source URL.

Publish a package

Prerequisites:

When publishing packages:

With NuGet CLI

Prerequisites:

To publish a package, run the following command:`

nuget push <package_file> -Source <source_name>

Replace:

For example:

nuget push MyPackage.1.0.0.nupkg -Source gitlab
With .NET CLI

History

Prerequisites:

To publish a package, run the following command:

dotnet nuget push <package_file> --source <source_name>

Replace:

For example:

dotnet nuget push MyPackage.1.0.0.nupkg --source gitlab

You can publish a package using the --api-key option instead of username and password:

dotnet nuget push <package_file> --source <source_url> --api-key <personal_access_token>

Replace:

For example:

dotnet nuget push MyPackage.1.0.0.nupkg --source https://gitlab.example.com/api/v4/projects/<project_id>/packages/nuget/index.json --api-key <personal_access_token>
With Chocolatey CLI

History

Prerequisites:

To publish a package with the Chocolatey CLI, run the following command:

choco push <package_file> --source <source_url> --api-key <gitlab_personal_access_token, deploy_token or job token>

Replace:

For example:

choco push MyPackage.1.0.0.nupkg --source "https://gitlab.example.com/api/v4/projects/<project_id>/packages/nuget/v2" --api-key <personal_access_token>
With a CI/CD pipeline

If you’re publishing NuGet packages with GitLab CI/CD, you can use a CI_JOB_TOKEN predefined variable instead of a personal access token or deploy token. The job token inherits the permissions of the user or member that generates the pipeline.

The examples in the following sections address common NuGet publishing workflows when using a CI/CD pipeline.

Publish packages when the default branch is updated

To publish new packages each time the main branch is updated:

  1. In the .gitlab-ci.yml file of your project, add the following deploy job:

    default:
      # Updated to a more current SDK version
      image: mcr.microsoft.com/dotnet/sdk:7.0
    
    stages:
      - deploy
    
    deploy:
      stage: deploy
      script:
        # Build the package in Release configuration
        - dotnet pack -c Release
        # Configure GitLab package registry as a NuGet source
        - dotnet nuget add source "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
        # Push the package to the project's package registry
        - dotnet nuget push "bin/Release/*.nupkg" --source gitlab
      rules:
        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH  # Only run on the main branch
      environment: production
  2. Commit the changes and push them to your GitLab repository to trigger a new CI/CD build.

Publish versioned packages with Git tags

To publish versioned NuGet packages with Git tags:

  1. In the .gitlab-ci.yml file of your project, add the following deploy job:

    publish-tagged-version:
      stage: deploy
      script:
        # Use the Git tag as the package version
        - dotnet pack -c Release /p:Version=${CI_COMMIT_TAG} /p:PackageVersion=${CI_COMMIT_TAG}
        # Configure GitLab package registry as a NuGet source
        - dotnet nuget add source "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
        # Push the package to the project's package registry
        - dotnet nuget push "bin/Release/*.nupkg" --source gitlab
      rules:
        - if: $CI_COMMIT_TAG  # Only run when a tag is pushed
  2. Commit the changes and push them to your GitLab repository.

  3. Push a Git tag to trigger a new CI/CD build.

Publish conditionally for different environments

You can configure the CI/CD pipeline to conditionally publish NuGet packages to different environments depending on your use case.

To conditionally publish NuGet packages for development and production environments:

  1. In the .gitlab-ci.yml file of your project, add the following deploy jobs:

      # Publish development/preview packages
    publish-dev:
      stage: deploy
      script:
        # Create a development version with pipeline ID for uniqueness
        - VERSION="0.0.1-dev.${CI_PIPELINE_IID}"
        - dotnet pack -c Release /p:Version=$VERSION /p:PackageVersion=$VERSION
        # Configure GitLab package registry as a NuGet source
        - dotnet nuget add source "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
        # Push the package to the project's package registry
        - dotnet nuget push "bin/Release/*.nupkg" --source gitlab
      rules:
        - if: $CI_COMMIT_BRANCH == "develop"
      environment: development
    
      # Publish stable release packages
    publish-release:
      stage: deploy
      script:
        - dotnet pack -c Release
        # Configure GitLab package registry as a NuGet source
        - dotnet nuget add source "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
        # Push the package to the project's package registry
        - dotnet nuget push "bin/Release/*.nupkg" --source gitlab
      rules:
        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      environment: production
  2. Commit the changes and push them to your GitLab repository.

    With this CI/CD configuration:

Turn off duplicate NuGet packages

History

You can publish multiple packages with the same name and version.

To prevent group members and users from publishing duplicate NuGet packages, turn off the Allow duplicates setting:

  1. On the left sidebar, select Search or go to and find your group.
  2. Select Settings > Packages and registries.
  3. In the NuGet row of the Duplicate packages table, turn off the Allow duplicates toggle.
  4. Optional. In the Exceptions text box, enter a regular expression that matches the names and versions of packages to allow.

You can also turn off duplicate NuGet packages with the nuget_duplicates_allowed setting in the GraphQL API.

If the .nuspec file is not located in the root of the package or the beginning of the archive, the package might not be immediately recognized as a duplicate. When it is inevitably recognized as a duplicate, an error displays in the Package manager page.

Install a package

The GitLab package registry can contain multiple packages with the same name and version. If you install a duplicate package, the latest published package is retrieved.

Prerequisites:

From the command line

Install the latest version of a package by running this command:

nuget install <package_id> -OutputDirectory <output_directory> \
  -Version <package_version> \
  -Source <source_name>

If the GitLab package registry has a NuGet package with the same name as a package at a different source, verify the order in which dotnet checks sources during install. This behavior is defined in the nuget.config file.

Install the latest version of a package by running this command:

dotnet add package <package_id> \
       -v <package_version>
With NuGet v2 feed

History

Prerequisites:

To install a package with the Chocolatey CLI:

choco install <package_id> -Source <source_url> -Version <package_version>

For example:

choco install MyPackage -Source gitlab -Version 1.0.2

# or

choco install MyPackage -Source "https://gitlab.example.com/api/v4/projects/<project_id>/packages/nuget/v2" -u <username> -p <personal_access_token> -Version 1.0.2

To upgrade a package with the Chocolatey CLI:

choco upgrade <package_id> -Source <source_url> -Version <package_version>

For example:

choco upgrade MyPackage -Source gitlab -Version 1.0.3
Delete a package

History

Deleting a package is a permanent action that cannot be undone.

Prerequisites:

To delete a package with the NuGet CLI:

nuget delete <package_id> <package_version> -Source <source_name> -ApiKey <personal_access_token>

For example:

nuget delete MyPackage 1.0.0 -Source gitlab -ApiKey <personal_access_token>
Symbol packages

GitLab can consume symbol files from the NuGet package registry. You can use the GitLab package registry as a symbol server to debug your NuGet packages.

Whenever you publish a NuGet package file (.nupkg), symbol package files (.snupkg) are uploaded automatically to the NuGet package registry.

You can also push them manually:

nuget push My.Package.snupkg -Source <source_name>
Use the GitLab endpoint for symbol files

History

GitLab package registry provides a special symbolfiles endpoint that you can configure with your project or group endpoint:

The symbolfiles endpoint is the source where a configured debugger can push symbol files.

Use the package registry as a symbol server

To use the symbol server:

  1. Enable the nuget_symbol_server_enabled namespace setting with the GraphQL API.
  2. Configure your debugger to use the symbol server.

For example, to configure Visual Studio as your debugger:

  1. Select Tools > Preferences.
  2. Select Debugger > Symbol sources.
  3. Select Add.
  4. Enter the symbol server URL.
  5. Select Add Source.

After you configure the debugger, you can debug your application as usual. The debugger automatically downloads the symbol PDB files from the package registry if they’re available.

Consume symbol packages

When the debugger is configured to consume symbol packages, the debugger sends the following information in a request:

The GitLab server matches this information to a symbol file and returns it.

Keep in mind that:

Supported CLI commands

History

The GitLab NuGet repository supports the following commands for the NuGet CLI (nuget) and the .NET CLI (dotnet):

NuGet .NET Description nuget push dotnet nuget push Upload a package to the registry. nuget install dotnet add Install a package from the registry. nuget delete dotnet nuget delete Delete a package from the registry. Troubleshooting

When working with NuGet packages, you might encounter the following issues.

Clear the NuGet cache

To improve performance, NuGet caches package files. If you encounter storage issues, clear the cache with the following command:

Errors when publishing NuGet packages in a Docker-based GitLab installation

You might get the following error messages when publishing NuGet packages:

Webhook requests to local network addresses are blocked to prevent exploitation of internal web services.

To resolve these errors, change your network settings to allow webhook and integration requests to the local network.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4