TExcelTAD
Home › .NET Builds: MSBuild & NuGet › Toolkit: Package Explorer & Hosted Feeds

Toolkit: Package Explorer & Hosted Feeds

Packages are the interface between teams. This lesson covers the tools for looking inside them, for checking their signatures, and the services that host private feeds. The hosted services need accounts and network access, so they are described, not run; the inspection steps are real.

Looking inside a package

NuGet Package Explorer (a Windows app, from the Microsoft Store or winget, and a web version at nuget.info) opens any .nupkg, from a file or straight from a feed. It shows the metadata, the file tree per target framework, the dependencies, the signature, and a health panel: "Source Link: valid", "Deterministic (dll/exe): valid", "Compiler flags: present". Those checks are what a well-built package should pass, and they're the ones the previous lessons set up.

Without a GUI, a .nupkg is a zip and a nuspec is XML, so a short shell function goes a long way:

bash · try it yourself
nupkg() {  # nupkg <file>: a text-mode package explorer
  local spec
  spec=$(unzip -Z1 "$1" | grep -m1 '\.nuspec
  

)
  unzip -p "$1" "$spec" | tr -d '\r' | grep -E -o '<(id|version|authors|license type="[a-z]*"|description)>[^<]*' | sed 's/<\([a-z]*\)[^>]*>/\1: /'
  echo "dependencies:"
  unzip -p "$1" "$spec" | grep -E -o '(group targetFramework|dependency id)="[^"]*"( version="[^"]*")?' | sed 's/group targetFramework=/  for /; s/dependency id=/    /'
  echo "files:"
  unzip -Z1 "$1" | grep -E '^(lib|ref|build|buildTransitive|analyzers|tools|runtimes)/' | sed 's/^/  /'
}
nupkg /opt/nuget-feed/xunit.assert.2.9.3.nupkg
id: xunit.assert
version: 2.9.3
authors: jnewkirk,bradwilson
license: Apache-2.0
description: Includes the assertion library from xUnit.net (xunit.assert.dll). Supports .NET Standard 1.1+ and .NET 6.0+.
dependencies:
  for ".NETFramework4.5.2"
  for ".NETStandard1.1"
    "NETStandard.Library" version="1.6.1"
  for ".NETStandard2.0"
  for "net6.0"
files:
  lib/netstandard1.1/xunit.assert.dll
  lib/netstandard1.1/xunit.assert.xml
  lib/net6.0/xunit.assert.dll
  lib/net6.0/xunit.assert.xml

unzip -Z1 lists names only; unzip -p prints a member to stdout. For JSON-minded inspection, dotnet package search <term> --source <feed> queries a v3 feed (it needs an HTTP feed with a search service, so not a folder feed).

Signatures

Packages on nuget.org carry a repository signature (nuget.org's countersignature, added on upload) and often an author signature (the publisher's code-signing certificate). dotnet nuget verify checks them:

bash · try it yourself
export NUGET_CERT_REVOCATION_MODE=offline
dotnet nuget verify --all /opt/nuget-feed/Newtonsoft.Json.13.0.4.nupkg 2>&1 | grep -E 'Signature type|Subject Name|NU3' | sed 's/^ *//' | cut -c1-90
echo "exit: ${PIPESTATUS[0]}"
mkdir lib && cd lib
cat > lib.csproj <<'XML'
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <PackageId>Ada.Unsigned</PackageId>
  </PropertyGroup>
</Project>
XML
echo 'public class U { }' > U.cs
dotnet pack -o out -nologo -v:q
dotnet nuget verify --all out/Ada.Unsigned.1.0.0.nupkg 2>&1 | grep -E 'NU3|Package signature'
echo "exit: ${PIPESTATUS[0]}"
Signature type: Author
Subject Name: CN=Json.NET (.NET Foundation), O=Json.NET (.NET Foundation), L=Redmond, S=Wa
Signature type: Repository
Subject Name: CN=NuGet.org Repository by Microsoft, O=NuGet.org Repository by Microsoft, L
exit: 0
error: NU3004: The package is not signed.
Package signature validation failed.
exit: 1
  • Newtonsoft.Json has an author signature (the Json.NET (.NET Foundation) certificate; the long subject line is cut at 90 characters here) and nuget.org's repository countersignature. NUGET_CERT_REVOCATION_MODE=offline stops NuGet from contacting certificate revocation servers, which this machine can't reach; online, leave it at the default.
  • Our own package is unsigned (NU3004). Signing needs a code-signing certificate: dotnet nuget sign out/*.nupkg --certificate-path cert.pfx --timestamper http://timestamp.digicert.com (not run here: no certificate and no timestamp server).
  • To enforce signatures on restore, set signatureValidationMode to require in nuget.config and list trustedSigners (by repository or author certificate fingerprint). Combined with source mapping that's the strongest supply-chain setting NuGet offers.

Hosted feeds

Service Notes
nuget.org the public gallery; API keys scoped per package and glob, trusted publishing from GitHub Actions, package id prefix reservation (a check mark for verified owners), symbol server for .snupkg
Azure Artifacts (Azure DevOps) private NuGet (and npm, Maven, Python) feeds; upstream sources proxy and cache nuget.org through the same feed; views (@prerelease, @release) promote versions without republishing; authentication through the Azure Artifacts Credential Provider or a PAT
GitHub Packages https://nuget.pkg.github.com/<owner>/index.json; push with a token that has write:packages (GITHUB_TOKEN in Actions); packages are linked to a repository and inherit its visibility
JFrog Artifactory, Sonatype Nexus, ProGet self-hosted or SaaS repository managers for every ecosystem; virtual repositories combine a local feed and a proxy of nuget.org
BaGetter (open source) a lightweight self-hosted NuGet server, handy for small teams and tests
a folder or file share what this course uses: zero setup, but no authentication, no immutability (a push overwrites) and slow with thousands of packages

Whichever you use, the client side is the same three pieces: a source in nuget.config, credentials outside the repository, and dotnet nuget push. A typical CI publish step for a hosted feed looks like this (sample, not run):

yaml
- run: dotnet pack -c Release -o out -p:ContinuousIntegrationBuild=true
- run: dotnet nuget push "out/*.nupkg" --source "https://nuget.pkg.github.com/ada/index.json" --api-key "${{ secrets.GITHUB_TOKEN }}" --skip-duplicate

--skip-duplicate makes a re-run of the same CI job succeed instead of failing on "version already exists", which hosted feeds report as HTTP 409.

Test yourself

What does nuget.org add to every package uploaded to it?

  1. An author signature
  2. A repository countersignature
  3. A SourceLink map
  4. A lock file

Which Azure Artifacts feature lets one feed serve both your private packages and cached nuget.org packages?

  1. Views
  2. Upstream sources
  3. Retention policies
  4. Symbol server

Why add --skip-duplicate to dotnet nuget push in CI?

  1. To push faster
  2. So that re-running a job doesn't fail when the version is already on the feed
  3. To overwrite existing versions
  4. To skip symbol packages