Creating and Publishing .NET NuGet Packages


SETP-1: Prerequisites
Install .NET SDK (8.0 or newer recommended)
Create a free NuGet.org account
Verify installation: After a successful installation, you could verify by the cmd/bash.
dotnet --version
SETP-2: Create a class library project
Using this command, a project named MyAwesomePackage
will be created.
dotnet new classlib -n MyAwesomePackage
cd MyAwesomePackage
SETP-3: Open an Editor and Add your code
XML comments are necessary for proper documentation.
namespace MyAwesomePackage;
/// <summary>
/// Provides basic arithmetic operations
/// </summary>
public class Calculator
{
/// <summary>
/// Adds two integers
/// </summary>
/// <param name="a">First number</param>
/// <param name="b">Second number</param>
/// <returns>Sum of a and b</returns>
public int Add(int a, int b) => a + b;
// Add similar documentation for Multiply
}
SETP-4: Configure Package Metadata
Here is a basic project setup file, MyAwesomePackage.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<!-- Core Package Metadata -->
<PackageId>MyAwesomePackage</PackageId>
<Version>1.0.1</Version>
<Authors>bishojit</Authors>
<Company>BIKIRAN</Company>
<Description>Utility functions for common operations</Description>
<PackageTags>utilities helper tools</PackageTags>
<!-- Recommended Additions -->
<PackageProjectUrl>https://github.com/bikirandev/bikiran.utils</PackageProjectUrl>
<RepositoryUrl>https://github.com/bikirandev/bikiran.utils.git</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<!-- Add below existing PackageTags -->
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<!-- Add NuGet.Protocol package reference -->
<PackageReference Include="NuGet.Protocol" Version="6.13.2" />
</ItemGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>
</Project>
STEP-5: Build the Package
After developing all the operations, you need to build the package before publishing it.
dotnet build
STEP-6: Create NuGet Package
Make sure to fix all errors and warnings before publishing.
dotnet pack --configuration Release
STEP-7: Requirements before publishing
Add a LICENSE File (Required)
Add README.md (Required)
I repeat, must add XML comment documentation on each class.
Add Package Icon (Optional)
STEP-8: Publish to NuGet.org
Log in > Click Upload (On Top Navigation Bar)
Locate your file and upload it.
After a successful upload, complete the form.
After a few minutes, the Package will be approved.
Important Notes:
Versioning: Increment
<Version>
before each new releaseThe package ID must be unique across NuGet.org
Recommended: Use Semantic Versioning
For private feeds: Change
--source
to your feed URL
Next Steps:
Add documentation in README.md
Consider adding:
XML documentation comments
License file
Icon
Release notes
CONTACT:
I’m Kumar Bishojit Paul, the Founder and CEO of BIKIRAN. If you need further assistance, please leave a comment. I’m interested in helping you.
Subscribe to my newsletter
Read articles from KUMAR BISHOJIT directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
