Packing & publishing to NuGet
Pack a library into a .nupkg and publish it. Fill minimal metadata, run dotnet pack, push with an API key, and follow safe publishing practices.
Packing & publishing to NuGet is a free C# Academy lesson on CoddyKit — lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C# Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Plan
Aim: Build and publish a NuGet package.
- Fill basic metadata in the project
- Run dotnet pack to get a .nupkg
- Use an API key to dotnet nuget push
- Follow safe publishing checks
Metadata to set
- PackageId: unique ID (e.g., Company.Widget)
- Version: MAJOR.MINOR.PATCH
- Authors, Description
- PackageLicenseExpression (e.g., MIT) or license file
- RepositoryUrl (optional but useful)
Identity preview
A package carries identity and version. This simple app reads the assembly name/version you will expose when packing.
using System;
using System.Reflection;
// Demo: show how a packed library exposes version and name.
// In real packaging, version/metadata come from the .csproj.
public class Program
{
public static void Main(string[] args)
{
Assembly asm = Assembly.GetExecutingAssembly();
Version ver = asm.GetName().Version;
string name = asm.GetName().Name;
Console.WriteLine("Assembly: " + name);
Console.WriteLine("Version: " + (ver == null ? "unknown" : ver.ToString()));
Console.WriteLine("Tip: Set PackageId/Version/Authors in the .csproj before packing.");
}
}
Pack & push steps
Workflow: restore → pack → push. Keep the API key safe and scoped.
using System;
// This code prints the typical pack workflow steps.
// Run them in your terminal; here we just echo the sequence.
public class Program
{
static void Print(string step)
{
Console.WriteLine(step);
}
public static void Main(string[] args)
{
Print("1) Ensure .csproj has PackageId/Version/Authors/Description");
Print("2) dotnet restore");
Print("3) dotnet pack -c Release");
Print(" -> bin/Release/<tfm>/*.nupkg");
Print("4) Get an API key from your NuGet server");
Print("5) dotnet nuget push bin/Release/*.nupkg --api-key <KEY> --source <URL or nuget.org>");
Print("Done: package available for consumers.");
}
}
Publishing tips
- Test the package locally before push (install from local source)
- Keep API keys secret; prefer environment variables
- Provide symbols/source info if you want better debugging
- Write a short README and changelog
Troubleshooting
- ID already exists → choose a unique PackageId
- Missing license → add PackageLicenseExpression or license file
- No description → add a short product summary
- Wrong version → bump MAJOR/MINOR/PATCH correctly
Pack command
Recap
Recap: Fill project metadata, run dotnet pack to create a .nupkg, then dotnet nuget push with your API key. Verify content and keep credentials safe.
Frequently asked questions
Is the “Packing & publishing to NuGet” lesson free?
Yes — the full text of “Packing & publishing to NuGet” is free to read here on the web, and the C# Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C# Academy course, upgrade to CoddyKit PRO.
What will I learn in “Packing & publishing to NuGet”?
Pack a library into a .nupkg and publish it. Fill minimal metadata, run dotnet pack, push with an API key, and follow safe publishing practices. You practise C# Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C# Academy?
No prior experience is required. C# Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Packing & publishing to NuGet” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C# Academy lesson?
Yes. Every C# Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Library vs app .csproj, semantic versioning
- Packing & publishing to NuGet
- Multi-targeting