Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.
ArtifactsRegistry TypesGetting Started

NuGet

Create a NuGet registry, generate an identity token, then publish and install private NuGet packages with the NuGet CLI, the .NET CLI, or PowerShell.

Use a NuGet registry to host private NuGet packages. The registry works with the NuGet CLI, the .NET CLI, Visual Studio, and PowerShell.

What you will learn from this topic

By the end of this quickstart guide, you will be able to:

  • Create a registry in Harness Artifacts.

  • Publish a package to the registry.

  • Install the package from the registry, and confirm the working.

Before you begin

  • Install the NuGet CLI (nuget), the .NET CLI (dotnet), Visual Studio, or PowerShell with the Microsoft.PowerShell.PSResourceGet module on your local machine.

  • Install the Harness CLI (hc). You use it to publish packages to your registry.

  • Make sure you have access to a Harness account with permission to create registries and connectors.

Create a NuGet Registry

To create a NuGet registry, perform the following steps:

  1. In Artifact Registry, select Registries.

  2. Select + Create Registry.

  3. Specify the Registry name.

Registry name criteria

The registry name must start with a letter, can only contain lowercase alphanumerics, _, ., and -, and must be unique to your Harness account.

  1. Optionally, add a Description.

  2. Choose visibility between Public and Private. The default is Private.

Private registries

A private NuGet registry restricts package push and pull access to users with the required permissions in your Harness account.

  1. Select NuGet as the Registry type.

  2. Click Save.

  3. Select Create to finalize.

Configure an upstream proxy (optional)

An upstream proxy allows your registry to fetch NuGet packages from external sources, such as NuGet.org, when they are not available locally. The default upstream is NuGet.org.

Create upstream proxy

To create an upstream proxy, perform the following steps:

  1. In Artifact Registry, select Registries.

  2. Select the drop-down next to + Create Registry and select Upstream Proxy.

  3. Specify the Registry name.

  4. Optionally, add a Description.

  5. Choose visibility between Public and Private. The default is Private.

  6. Select NuGet as the Registry type.

  7. Select the Source: NuGet.org or Custom.

    • If you select Custom, specify the Remote registry URL (for example, https://api.nuget.org/v3/index.json).

  8. Select the Authentication method.

    • Username and password: Specify the username and password. Use an existing secret, or create a new secret by specifying the Name and entering the Secret text.

    • Anonymous: No credentials required. This works for public NuGet feeds.

  9. Optionally, configure Metadata configuration.

    • Metadata cache TTL (seconds): How long Harness caches package metadata from the upstream source before it checks the source again.

    • Negative cache TTL (seconds): How long Harness caches a package-not-found response from the upstream source before it checks the source again.

  10. Select Create to finalize.

Configure the upstream proxy in your registry

To configure the upstream proxy in your registry, perform the following steps:

  1. In Artifact Registry, select an existing NuGet registry.

  2. Navigate to the Configuration tab.

  3. Select Edit in the Upstream proxy section.

  4. Click + Add upstream proxy.

  5. Select the required proxy from the list.

  6. Click Apply.

  7. Select Update to finalize.

Upstream proxy caching

If a package is not found in your Harness registry, the upstream proxy fetches it from NuGet.org or your custom source and caches it.

NuGet client setup

In your NuGet Artifact, select the registry, then select Set Up Client. The dialog gives you an identity token, then setup instructions for the NuGet CLI, the .NET CLI, Visual Studio, or PowerShell.

Generate an identity token

An identity token serves as the password for authenticating with the registry.

  1. In your NuGet Artifact, select Set Up Client.

  2. Select Generate Token.

  3. Select an Expiration for the token:

    • 30 Days

    • 90 Days

    • 180 Days

    • Custom

  4. Copy the token. You use it in the following steps in place of <TOKEN>.

Token expiration

The identity token stops working after the expiration you select. Generate a new token and update your client configuration before the current token expires.

Configure the client

Select NuGet, Dotnet, Visual Studio, or PowerShell for your client. In the code samples, replace the values in angle brackets with your own values.

1. Configure authentication

Add the Harness Registry as a package source:

NuGet V2 clients

For a NuGet V2 client, use https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/nuget/ instead of the V3 index URL.

2. Publish the package

Publish your package:

Publishing to a nested path

To publish a package under a sub-directory in the registry, target that path directly:

3. Use the package

Install a package from the registry:

1. Configure authentication

Add the Harness Registry as a package source:

NuGet V2 clients

For a NuGet V2 client, use https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/nuget/ instead of the V3 index URL.

2. Publish the package

Publish your package:

Publishing to a nested path

To publish a package under a sub-directory in the registry, target that path directly:

3. Use the package

Add a package reference to your project:

1. Configure authentication

  1. Select Tools > NuGet Package Manager > Package Manager Settings.

  2. Select Package Sources in the left panel. Note the location of your NuGet.Config file shown at the top of the window. You can edit this file directly instead of using the UI.

  3. Select + to add a new package source.

  4. Set the Name to harness.

  5. Set the Source to https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/nuget/index.json.

  6. Select Update, then select OK.

Alternatively, add the source directly to your NuGet.Config file:

Client setup details

Copy this NuGet.Config block directly from Set Up Client in your registry, with your account ID and registry name already filled in.

2. Publish the package

Select Build > Pack on your project to produce a .nupkg file, then push it from a terminal using the .NET CLI:

3. Use the package

In NuGet Package Manager, select the harness source, then browse and install the package in your project.

1. Configure authentication

Register the Harness Registry as a PowerShell repository:

NuGet V2 upstream registries

For NuGet V2 upstream registries, such as the PowerShell Gallery, use https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/nuget/v2 instead of the V3 index URL.

2. Publish the package

Publish a module or script to the registry:

3. Use the package

Install a module from the registry:

Setup verification

Confirm that your registry serves the package you published. To verify your setup, perform the following steps:

  1. In a new project with no packages folder and no cached NuGet entries for the Harness source, install or reference the package you published.

  2. Confirm that the client downloaded the package from your Harness registry address, which is shown in Set Up Client.

  3. In Harness, open your registry and confirm that the package and version appear in the package list.

If a step fails, go to Troubleshooting to resolve common authentication and resolution issues before you retry.

Pipeline automation (optional)

Publishing from a pipeline gives you a repeatable release process. Run the publish step when you create a version tag, so each release maps to one version in the registry.

The following Run step packs and pushes a NuGet package using the version from the release tag. Store the identity token as a Harness secret, and do not write it into the pipeline YAML.

Troubleshooting

`nuget install` or `dotnet add package` fails with `401` or `403`

Check that the registry address in your client configuration matches the one shown in Set Up Client, and that the identity token is the one you generated there. If the token has expired or was revoked, generate a new one and update your client configuration.

`nuget push` or `dotnet nuget push` returns `409 Conflict`

NuGet package versions are immutable after publish. Choose a new version, or delete the existing version only if your registry retention and lifecycle policies allow it.

`nuget install` cannot find the package or resolves an outdated version

Check that the package ID and version match exactly what you published. Also, check that the registry name and account ID in your client configuration are correct.

Set Up Client does not show publish instructions on an upstream proxy

An upstream proxy registry is pull-only, so Set Up Client omits publish instructions for it. To publish a package, publish it to a separate private or public NuGet registry, or let the upstream proxy cache public packages automatically when a client requests them.

A client continues to resolve a cached older version after a new publish

NuGet caches resolved packages locally. Clear the cache with nuget locals all -clear or dotnet nuget locals all --clear, then reinstall the package.

Next steps

Last updated

Was this helpful?