Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/harness/harness-cli/llms.txt

Use this file to discover all available pages before exploring further.

Harness Artifact Registry provides support for NuGet packages, allowing you to host private .NET libraries and applications.

Overview

NuGet registry features:
  • NuGet V3 protocol support
  • .nupkg package format
  • Version management
  • Nested directory support for package uploads
  • Integration with dotnet CLI and NuGet client

Pushing NuGet packages

Use the hc artifact push nuget command:
hc artifact push nuget <registry-name> <nupkg-file-path> \
  --pkg-url <pkg-url>

Optional flags

--path
string
Path for nested directories within the package. Useful for organizing related packages
--pkg-url
string
required
Base URL for the package service

Building NuGet packages

1

Create or update .csproj

Ensure your project file has package metadata:
MyLibrary.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <PackageId>MyCompany.MyLibrary</PackageId>
    <Version>1.0.0</Version>
    <Authors>Your Name</Authors>
    <Description>My awesome library</Description>
  </PropertyGroup>
</Project>
2

Build the package

Use dotnet CLI to create the .nupkg:
dotnet pack -c Release
3

Upload to registry

Push the package:
hc artifact push nuget my-registry ./bin/Release/MyLibrary.1.0.0.nupkg \
  --pkg-url https://app.harness.io/registry/pkg

Installing NuGet packages

Configure NuGet to use your Harness registry:

Add package source

dotnet nuget add source https://<registry-url>/v3/index.json \
  --name Harness \
  --username <username> \
  --password <harness-api-token> \
  --store-password-in-clear-text

Install packages

# Install a package
dotnet add package MyCompany.MyLibrary

# Install specific version
dotnet add package MyCompany.MyLibrary --version 1.0.0

Examples

# Build and push a NuGet package
dotnet pack -c Release
hc artifact push nuget my-registry ./bin/Release/MyLib.1.0.0.nupkg \
  --pkg-url https://app.harness.io/registry/pkg

NuGet.config configuration

Create a NuGet.config file in your solution or repository root:
NuGet.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="Harness" value="https://<registry-url>/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
  
  <packageSourceCredentials>
    <Harness>
      <add key="Username" value="your-username" />
      <add key="ClearTextPassword" value="your-harness-token" />
    </Harness>
  </packageSourceCredentials>
</configuration>
Store credentials securely. Use environment variables or credential providers in CI/CD environments.

CI/CD integration

- name: Build and publish
  run: |
    dotnet pack -c Release
    hc artifact push nuget my-registry ./bin/Release/*.nupkg \
      --pkg-url https://app.harness.io/registry/pkg
  env:
    HARNESS_API_KEY: ${{ secrets.HARNESS_API_KEY }}

Package versioning

NuGet uses semantic versioning (SemVer 2.0):
  • Release: 1.0.0
  • Pre-release: 1.0.0-alpha, 1.0.0-beta.1
  • Build metadata: 1.0.0+20231201
Set version in .csproj:
<PropertyGroup>
  <Version>1.0.0</Version>
  <!-- Or use MSBuild properties -->
  <Version>$(GitVersion)</Version>
</PropertyGroup>

Troubleshooting

Verify your credentials are configured:
# List configured sources
dotnet nuget list source

# Update credentials
dotnet nuget update source Harness \
  --username <username> \
  --password <new-token> \
  --store-password-in-clear-text
Check the package was uploaded successfully:
hc artifact list --registry my-registry --format json
NuGet doesn’t allow re-uploading the same version:
# Increment version
dotnet pack -c Release -p:Version=1.0.1

See also

Build docs developers (and LLMs) love