Configuring NuGet to work with a SourceCraft registry

  1. Create a personal access token (PAT).

  2. Create environment variables named REGISTRY_USERNAME and REGISTRY_PASSWORD containing data for authentication with a personal access token (PAT):

    export REGISTRY_USERNAME="iam"
    export REGISTRY_PASSWORD="<personal_access_token>"
    
  3. Set up the NuGet configuration file:

    To edit the NuGet configuration file using the dotnet CLI, run this command:

    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
    

    Tip

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

    To edit the NuGet configuration file using the NuGet CLI, 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
    

    Tip

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

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

    2. Update the configuration in the file as follows:

      <?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>
      

      Tip

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

  4. To push the prepared NuGet package to a SourceCraft registry, run this command:

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

    Result:

    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.
    
  5. To install the NuGet package from the SourceCraft registry, run this command:

    dotnet add package <package_name> \
      --source "sourcecraft-registry"
    
    nuget install <package_name> \
      -Source "sourcecraft-registry"
    

See also