Use NuGet with dotnet
NuGet in CloudRepo gives a .NET team its own packages and packages from nuget.org in one source. dotnet restores and pushes with the token you already have. The token stays in your environment, never in a file.
Create your repositories
Section titled “Create your repositories”In the admin portal, create three NuGet repositories:
- A hosted repository. It holds the packages you push.
- A proxy of nuget.org. It fetches public packages and keeps a copy.
- A group of the two. One URL serves both.
You also need a repository token that covers all three. Repository Tokens shows how to make one. The username is the email address of the account that made the token.
Set up dotnet
Section titled “Set up dotnet”Here is your nuget.config. Put your group’s name in place of your-repo:
<?xml version="1.0" encoding="utf-8"?><configuration> <packageSources> <clear /> <add key="cloudrepo" value="https://your-org.mycloudrepo.io/repositories/your-repo/index.json" protocolVersion="3" /> </packageSources> <auditSources> <clear /> <add key="nuget.org-audit" value="https://data.nuget.org/v3/index.json" /> </auditSources> <packageSourceCredentials> <cloudrepo> <add key="Username" value="you@example.com" /> <add key="ClearTextPassword" value="%CLOUDREPO_TOKEN%" /> </cloudrepo> </packageSourceCredentials></configuration>Save this file beside your solution. It holds no token, so you can commit it. <clear /> makes the group your only
source, so every package comes through CloudRepo.
Restore your packages
Section titled “Restore your packages”Set CLOUDREPO_TOKEN to your repository token first, in your shell or as a CI secret. Without it, the restore fails with a 401. Then restore:
dotnet restoreAdd a package
Section titled “Add a package”Add a package at the version you pick:
dotnet add package Newtonsoft.Json --version 13.0.3Or leave the version off, and dotnet picks the newest stable one:
dotnet add package Newtonsoft.JsonPush a package
Section titled “Push a package”Push to your hosted repository. A group or a proxy takes no push, and dotnet says it “does not support updating packages”.
A package can be up to 250 MiB, the same limit as nuget.org. A bigger push is refused with a message that says so.
Add the hosted repository to your nuget.config as a second source. Put your hosted repository’s name in place of
your-hosted-repo:
<?xml version="1.0" encoding="utf-8"?><configuration> <packageSources> <clear /> <add key="cloudrepo" value="https://your-org.mycloudrepo.io/repositories/your-repo/index.json" protocolVersion="3" /> <add key="cloudrepo-push" value="https://your-org.mycloudrepo.io/repositories/your-hosted-repo/index.json" protocolVersion="3" /> </packageSources> <auditSources> <clear /> <add key="nuget.org-audit" value="https://data.nuget.org/v3/index.json" /> </auditSources> <packageSourceCredentials> <cloudrepo> <add key="Username" value="you@example.com" /> <add key="ClearTextPassword" value="%CLOUDREPO_TOKEN%" /> </cloudrepo> <cloudrepo-push> <add key="Username" value="you@example.com" /> <add key="ClearTextPassword" value="%CLOUDREPO_TOKEN%" /> </cloudrepo-push> </packageSourceCredentials></configuration>Then pack your project and push it:
dotnet pack -c Release -o outdotnet nuget push out/*.nupkg --source cloudrepo-pushYour package now restores through the group, alongside packages from nuget.org.
Search and browse
Section titled “Search and browse”Search finds the packages in your hosted repositories and groups by name. In Visual Studio, open Manage NuGet
Packages, pick the cloudrepo source and use the Browse tab.
From a terminal, search in the folder that holds your nuget.config. Put part of a package name in place of Widgets:
dotnet package search Widgets --source https://your-org.mycloudrepo.io/repositories/your-repo/index.json --configfile nuget.config- Every word you search for must be part of the package name, in any case. Descriptions are not searched.
- You see only the packages your token can read.
- A group searches its hosted repositories, so it lists your own packages, not nuget.org’s.
dotnet add packagestill adds a nuget.org package through the group by name. - A proxy repository has no search.
- Each page of results holds up to 50 packages. With dotnet, page through more with
--skipand--take. - In a group, if your token can’t read a repository that comes before one it can in the group’s priority, search stops once it reaches 50 matching packages from the repositories after it. Pages past that point come back empty. This limits search only, not restore.
- Add
--prerelease, or tick Include prerelease in Visual Studio, to include prerelease versions. Without it, a package with no stable version still shows its prerelease ones.