Chainguard Libraries for .NET overview
Learn about Chainguard Libraries for .NET, providing enhanced security for NuGet dependencies
For the complete documentation index, see llms.txt.
Chainguard Libraries for .NET provides a registry of NuGet packages that have been scanned for malware and are subject to configurable policies. Switching an existing project requires only a registry configuration change – no changes to your application code or dependency versions.
This guide walks through migrating an existing .NET project to Chainguard Libraries, covering the two most common setups:
Before getting started, you need:
brew install --cask dotnet-sdkchainctl installed and authenticatedTo create an entitlement to Chainguard Libraries for .NET, run:
chainctl libraries entitlements create --ecosystems=DOTNETYou do not need to manually enable upstream fallback for .NET; the entitlement for .NET automatically includes Chainguard protections for upstream artifacts.
You can also configure a cooldown policy after you create the entitlement. For example, to create and enforce a policy for a 14-day cooldown:
chainctl libraries policy create --name=dotnet-cooldown-14d --cooldown-days=14
chainctl libraries policy enable dotnet-cooldown-14d --ecosystem=DOTNET --mode=ENFORCEIt can take up to 30 minutes for configured policies to take effect. Learn more about cooldown and other policies in the Libraries policies documentation.
Create a pull token for the .NET repository:
chainctl auth pull-token --repository=dotnet --ttl=8670hThe command returns a username and password. Use these values to authenticate NuGet to Chainguard Libraries.
Note: Do not commit the credentials to source control. Keep
nuget.configout of the repository when it contains literal credentials, or generate it at build time from secrets stored in your CI/CD system. For shared environments, use a dedicated machine identity or service account instead of a personal token when available.
Choose the setup that matches your organization. With direct access, your build tool connects to libraries.cgr.dev. With a repository manager, your build tool connects to a proxy that you configure to fetch from Chainguard Libraries.
NuGet reads package sources from nuget.config files at the project, solution, user, and machine levels. Before changing the configuration, list the sources currently in use:
dotnet nuget list sourceEdit or create a file named nuget.config in the project directory, alongside the .csproj file. Replace its contents with the following configuration, substituting the username and password with the values of your pull token:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="chainguard" value="https://libraries.cgr.dev/dotnet/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<chainguard>
<add key="Username" value="REPLACE WITH USERNAME FROM pull-token" />
<add key="ClearTextPassword" value="REPLACE WITH PASSWORD FROM pull-token" />
</chainguard>
</packageSourceCredentials>
</configuration>The <clear /> element removes previously configured package sources, including nuget.org. This prevents NuGet from silently falling back to nuget.org.
Confirm the active sources:
dotnet nuget list sourceThe expected output shows Chainguard as enabled:
Registered Sources:
1. chainguard [Enabled]
https://libraries.cgr.dev/dotnet/v3/index.jsonBefore you configure your project, set up your repository manager to proxy Chainguard Libraries for .NET. Follow the global configuration guide to add Chainguard Libraries as an upstream source. Once the repository manager is configured, point your project at its URL instead of libraries.cgr.dev.
From the project directory, create a NuGet configuration file:
dotnet new nugetconfigReplace its contents with the following configuration, substituting your repository manager URL and credentials:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="organization" value="https://repo.example.com/nuget/dotnet" />
</packageSources>
<packageSourceCredentials>
<organization>
<add key="Username" value="REPLACE WITH REPOSITORY MANAGER USERNAME" />
<add key="ClearTextPassword" value="REPLACE WITH REPOSITORY MANAGER PASSWORD" />
</organization>
</packageSourceCredentials>
</configuration>Authenticate with your repository manager credentials, not your Chainguard pull token. The pull token authenticates the repository manager to Chainguard; it does not authenticate individual build tools to the repository manager.
The <clear /> element removes previously configured package sources, including nuget.org. This prevents NuGet from silently falling back to nuget.org.
Confirm the active sources:
dotnet nuget list sourceThe expected output shows your repository manager as enabled:
Registered Sources:
1. organization [Enabled]
https://repo.example.com/nuget/dotnetBecause packages have previously been served from upstream, you must clear the NuGet HTTP cache and restore:
dotnet nuget locals http-cache --clear
dotnet restore --force --no-cache --verbosity normalThe output should include requests to the Chainguard endpoint. If you configured access through a repository manager, the output shows your repository manager URL instead. If the URL or credentials are incorrect, restore fails instead of using a cached package. Common errors include NU1301, NU1101, and HTTP 401 responses.
After restoring, build your project:
dotnet buildInspect the project assets file to confirm that your project is using Chainguard Libraries:
dotnet nuget list sourceThe expected output includes the Chainguard endpoint:
"sources": {
"https://libraries.cgr.dev/dotnet/v3/index.json": {}If you configured access through a repository manager, the sources entry shows your repository manager URL instead of libraries.cgr.dev, and must not contain nuget.org.
Last updated: 2026-09-29 16:31