---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.2
alternate:
  - https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configure-nuget.md
  - https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/configure-nuget.md
  - href: en/sourcecraft/operations/configure-nuget.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
title: Configuring NuGet to work with a SourceCraft registry
description: How to configure NuGet to work with a SourceCraft package registry.
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt


# Configuring NuGet to work with a SourceCraft registry

1. [Create](https://sourcecraft.dev/portal/docs/en/sourcecraft/security/pat.md#create) a personal access token (PAT).
1. Create environment variables named `REGISTRY_USERNAME` and `REGISTRY_PASSWORD` containing data for authentication with a personal access token (PAT):

    ```bash
    export REGISTRY_USERNAME="iam"
    export REGISTRY_PASSWORD="<PAT_personal_token>"
    ```

1. Set up the [NuGet](https://en.wikipedia.org/wiki/NuGet) configuration file:

    {% list tabs group=instructions %}

    - dotnet CLI {#dotnetcli}

      To edit the NuGet configuration file using the [dotnet CLI](https://learn.microsoft.com/en-us/nuget/reference/dotnet-commands), run this command:

      ```bash
      dotnet nuget add source "https://pkg.sourcecraft.tech/nuget/v3/<organization_slug>/<registry_ID>/index.json" \
        -n "sourcecraft-registry" \
        -u %REGISTRY_USERNAME% \
        -p %REGISTRY_PASSWORD% \
        --store-password-in-clear-text --protocol-version 3
      ```

      <!-- source: en/_includes/sourcecraft/get-slug-registry-id-notice.md -->
      {% note tip %}

      You can find the organization slug and registry ID on the registry page in the SourceCraft UI.

      {% endnote %}
      <!-- endsource: en/_includes/sourcecraft/get-slug-registry-id-notice.md -->

    - NuGet CLI {#nugetcli}

      To edit the NuGet configuration file using the [NuGet CLI](https://learn.microsoft.com/en-us/nuget/reference/nuget-exe-cli-reference), run the `nuget.exe` file with the following parameters:

      ```
      nuget sources add -Name "sourcecraft-registry" \
        -Source "https://pkg.sourcecraft.tech/nuget/v3/<organization_slug>/<registry_ID>/index.json" \
        -Username "%REGISTRY_USERNAME%" \
        -Password "%REGISTRY_PASSWORD%" \
        -StorePasswordInClearText -ProtocolVersion 3
      ```

      <!-- source: en/_includes/sourcecraft/get-slug-registry-id-notice.md -->
      {% note tip %}

      You can find the organization slug and registry ID on the registry page in the SourceCraft UI.

      {% endnote %}
      <!-- endsource: en/_includes/sourcecraft/get-slug-registry-id-notice.md -->

    - Manually {#manual}

      1. Open the NuGet [configuration file](https://learn.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior#config-file-locations-and-uses):

          {% note info %}

          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`.

          {% endnote %}
      1. Update the configuration in the file as follows:

          ```xml
          <?xml version="1.0" encoding="utf-8"?>
          <configuration>
            <packageSources>
              <add key="sourcecraft-registry" value="https://pkg.sourcecraft.tech/nuget/v3/<organization_slug>/<registry_ID>/index.json" protocolVersion="3" />
            </packageSources>

            <packageSourceCredentials>
              <sourcecraft-registry>
                <add key="Username" value="%REGISTRY_USERNAME%" />
                <add key="ClearTextPassword" value="%REGISTRY_PASSWORD%" />
              </sourcecraft-registry>
            </packageSourceCredentials>
          </configuration>
          ```

          <!-- source: en/_includes/sourcecraft/get-slug-registry-id-notice.md -->
          {% note tip %}

          You can find the organization slug and registry ID on the registry page in the SourceCraft UI.

          {% endnote %}
          <!-- endsource: en/_includes/sourcecraft/get-slug-registry-id-notice.md -->

    {% endlist %}

1. To push the [prepared](https://learn.microsoft.com/en-us/nuget/create-packages/overview-and-workflow) NuGet package to a SourceCraft registry, run this command:

    {% list tabs group=instructions %}

    - dotnet CLI {#dotnetcli}

      ```bash
      dotnet nuget push <path_to_package> \
        -s "sourcecraft-registry"
      ```

    - NuGet CLI {#nugetcli}

      ```bash
      nuget push <path_to_package> \
        -Source "sourcecraft-registry"
      ```

    {% endlist %}

    Result:

    ```text
    Pushing Nuget.Quickstart.1.0.0.nupkg to 'https://pkg.sourcecraft.tech/nuget/v3/myorg_cn10ckmq8hsk********/packages/'...
      PUT https://pkg.sourcecraft.tech/nuget/v3/myorg_cn10ckmq8hsk********/packages/
      Created https://pkg.sourcecraft.tech/nuget/v3/myorg_cn10ckmq8hsk********/packages/ 1534ms
    Your package was pushed.
    ```
1. To install the NuGet package from the SourceCraft registry, run this command:

    {% list tabs group=instructions %}

    - dotnet CLI {#dotnetcli}

      ```bash
      dotnet add package <package_name> \
        --source "sourcecraft-registry"
      ```

    - NuGet CLI {#nugetcli}

      ```bash
      nuget install <package_name> \
        -Source "sourcecraft-registry"
      ```

    {% endlist %}

#### Useful links {#see-also}

* [SourceCraft resource relationships](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/index.md)
* [Creating a registry in SourceCraft](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/packages-management.md)
* [Connecting a registry to a SourceCraft repository](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/connect-registry.md)
* [Configuring Maven to work with a SourceCraft registry](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configure-maven.md)
* [Configuring npm to work with a SourceCraft registry](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configure-npm.md)
* [Configuring PyPI to work with the SourceCraft registry](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configure-pypi.md)
* [Configuring Docker to work with a SourceCraft registry](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configure-docker.md)
