NuGet Package Manager streamlines .NET development by enabling quick installation, update, and management of libraries, saving time and reducing manual work. It handles dependencies automatically, ensuring compatibility and stability, while also supporting version control and private repositories. Integrated with tools like Visual Studio, NuGet promotes efficient teamwork and enhances productivity in managing open-source or internal packages.
1. What is Nuget?
Someone has already answered this, so check it out here: What is Nuget. If you’re unfamiliar with Nuget, you may not need to proceed with the following steps.
2. Register an account on nuget.org
Go to Nuget.org. You can log in using a Microsoft account (e.g., Office 365, Hotmail/Outlook/Live). Once logged in, click on your account name, select API Keys, and click Create to generate a key. Be sure to copy this key for step 3.
3. Build code and publish
Do what you like with your code, and here are some useful attributes to add in the .csproj file to display on Nuget. The GenerateDocumentationFile attribute keeps comments intact.
<Description>My Awesome Package</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>AwesomePackage</PackageId>
<Version>1.0.0</Version>
<Authors>Fun Corp</Authors>
<Company>Fun Inc</Company>
Once done, build the project and pack it. In the bin/Debug folder, you’ll see the file xxx.version.nupkg—this is what you’ll publish. Open a terminal, navigate to the folder with the .nupkg file, and run:
dotnet nuget push xxx.version.nupkg --api-key [your copied key] --source https://api.nuget.org/v3/index.json
4. Done
Go back to nuget.org, select Manage Packages, and check if your package is approved and listed. Here, you can also update Readme info and more.
Cover photo by Bernd 📷 Dittrich
Top comments (0)