Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this quickstart, you use Microsoft Visual Studio to create a NuGet package from a .NET class library. Then you publish the package to nuget.org by using a command-line interface (CLI) tool.
This quickstart is for Windows users only. If you're using a different platform, use the .NET CLI.
Prerequisites
Visual Studio 2026 with a .NET-related workload.
You can install the 2026 Community edition for free from visualstudio.microsoft.com, or you can use the Professional or Enterprise edition.
Visual Studio 2017 and later automatically include NuGet capabilities when you install a .NET-related workload.
The .NET CLI.
For Visual Studio 2017 and later, the .NET CLI is automatically installed with any .NET-related workload. You can also install the .NET SDK to get the .NET CLI. The .NET CLI is required for .NET projects that use the SDK-style format (and an SDK attribute). The default .NET class library template in Visual Studio 2017 and later uses the SDK attribute.
Important
If you're working with a non-SDK-style project, follow the procedures in Create and publish a package using Visual Studio (.NET Framework, Windows) instead to create and publish the package. For this article, the .NET CLI is recommended. Although you can publish any NuGet package by using the NuGet CLI, some of the steps in this article are specific to SDK-style projects and the .NET CLI. The NuGet CLI is used for non-SDK-style projects (typically .NET Framework projects).
A free account on nuget.org. You must register and confirm the account before you can upload a NuGet package.
The NuGet CLI. You can install it by downloading it from nuget.org. Add the nuget.exe file to a suitable folder, and add that folder to your
PATHenvironment variable.
Create a class library project
You can use an existing .NET class library project for the code you want to package, or you can create one by taking the following steps:
In Visual Studio, select File > New > Project/Solution.
In the Create a new project window, go to the search box and enter class library.
In the resulting list of project templates, select the Class Library template that meets the following criteria:
- Has the description A project for creating a class library that targets .NET or .NET Standard
- Has a C# tag
Select Next.
In the Configure your new project window, for Project name, enter AppLogger, and then select Next.
In the Additional information window, select an appropriate value for Framework, and then select Create.
If you're unsure which framework to select, the latest is a good choice, and can be easily changed later. For information about which framework to use, see When to target
netx.0vs.netstandard.(Optional) For this quickstart, you don't need to write any additional code for the NuGet package, because the template class library is sufficient to create a package. However, if you want to add some functional code to the package, include the following code:
namespace AppLogger { public class Logger { public void Log(string text) { Console.WriteLine(text); } } }
Configure package properties
After you create your project, you can configure the NuGet package properties by following these steps:
In Solution Explorer, select your project, and then select Project > <project-name> Properties, where <project-name> is the name of your project.
Expand the Package node, and then select General.
The Package node appears only for SDK-style projects in Visual Studio. If you're targeting a non-SDK style project (typically .NET Framework projects), either migrate the project, or see Create and publish a package using Visual Studio (.NET Framework, Windows) for step-by-step instructions.
For Package ID, give your package a unique ID.
Important
You must give the package an identifier that's unique across the host that you use, such as nuget.org. Otherwise, an error occurs. For this quickstart, we recommend including Sample or Test in the ID, because the publishing step makes the package publicly visible. For more information about selecting an ID, see Best practices for the package identifier.
Fill out any other desired properties. For packages built for public consumption, pay special attention to the Tags property, because tags help others find your package and understand what it does.
All the properties go into the .nuspec manifest that Visual Studio creates for the project. For a table that shows how Microsoft Build (MSBuild) properties in SDK-style projects map to .nuspec file properties, see pack target. For a description of .nuspec file properties, see .nuspec reference.
(Optional) To see the properties directly in the AppLogger.csproj project file, select Project > Edit Project File.
The AppLogger.csproj file opens in a new tab.
This option is available for projects that use the SDK-style attribute.
Run the pack command
To create a NuGet package from your project, follow these steps:
Select Build > Configuration Manager, and then set the Active solution configuration value to Release.
In Solution Explorer, right-click the AppLogger project, and then select Pack.
Visual Studio builds the project and creates the .nupkg file.
Examine the Output window for detailed information, including the path to the package file. In this example, the built assembly is in the bin\Release\net8.0 folder, which is appropriate for a .NET 8.0 target:
1>------ Build started: Project: AppLogger, Configuration: Release Any CPU ------ 1> AppLogger -> d:\proj\AppLogger\AppLogger\bin\Release\net8.0\AppLogger.dll 1> Successfully created package 'd:\proj\AppLogger\AppLogger\bin\Release\Contoso.App.Logger.Test.1.0.0.nupkg'. ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
If the Pack command is missing from the menu, your project probably isn't an SDK-style project. Take one of the following steps:
- Upgrade the project so that you can use the .NET CLI.
- Follow the instructions in Create and publish a package using Visual Studio (.NET Framework, Windows) to use the NuGet CLI to create and publish a NuGet package from your project.
(Optional) Generate package on build
You can configure Visual Studio to automatically generate the NuGet package when you build the project:
Select your project in Solution Explorer, and then select Project > <project-name> Properties, where <project-name> is the name of your project (AppLogger in this case).
Expand the Package node, select General, and then select Generate NuGet package on build.
Note
When you select this option, the extra time that's needed to generate the package increases the overall build time for your project.
(Optional) Pack with MSBuild
As an alternative to using the Pack menu command, you can use the msbuild -t:pack command to build a NuGet package from your project. NuGet 4.x+ and MSBuild 15.1+ support a pack target when your project contains the necessary package data.
With your project open in Solution Explorer, open a command prompt window by selecting Tools > Command Line > Developer Command Prompt.
The command prompt window opens in your project directory.
Run the following command:
msbuild -t:pack.
For more information, see Create a NuGet package using MSBuild.
Publish the package
After you create a .nupkg file, take the steps in the following sections to publish it to nuget.org. You can use the .NET CLI or the NuGet CLI for publishing. You also use an API key that you acquire from nuget.org.
Note
Nuget.org scans all uploaded packages for viruses and rejects any packages that contain viruses. Nuget.org also scans all existing listed packages periodically.
Packages you publish to nuget.org are publicly visible to other developers unless you unlist them. To host packages privately, see Hosting your own NuGet feeds.
Acquire your API key
Before you publish your NuGet package, create an API key:
Sign in to your nuget.org account or create an account if you don't have one already.
In the upper-right corner, select your user name, and then select API Keys.
Select Create, and then enter a name for your key.
Under Select Scopes, select Push.
Under Select Packages, for Glob Pattern, enter an asterisk (*).
Select Create.
Select Copy to copy the new key.
Important
- Always keep your API key a secret. The API key is like a password that anyone can use to manage packages on your behalf. Delete or regenerate your API key if it's accidentally revealed.
- Save your key in a secure location, because you can't copy the key again later. If you return to the API key page, you need to regenerate the key to copy it. You can also remove the API key if you no longer want to push packages.
Scoping provides a way to create separate API keys for different purposes. Each key has an expiration time frame, and you can scope the key to specific packages or glob patterns. You also scope each key to specific operations: Push new packages and package versions, push only new package versions, or unlist.
Through scoping, you can create API keys for different people who manage packages for your organization so they have only the permissions they need.
For more information, see Scoped API keys.
Publish by using the .NET CLI or NuGet CLI
You can use the .NET CLI or the NuGet CLI to push a package to the server and publish it. Go to the tab for the tool that you want to use.
The .NET CLI (dotnet.exe) is the recommended alternative to the NuGet CLI.
From the folder that contains the .nupkg file, run the following command. Replace <package-file> with the name of your .nupkg file, and replace <API-key> with your API key.
dotnet nuget push <package-file> --api-key <API-key> --source https://api.nuget.org/v3/index.json
The output shows the results of the publishing process:
Pushing <package-file> to 'https://www.nuget.org/api/v2/package'...
PUT https://www.nuget.org/api/v2/package/
Created https://www.nuget.org/api/v2/package/ 2891ms
Your package was pushed.
For more information, see dotnet nuget push.
Errors during publishing
When you run the push command, you sometimes encounter an error. For instance, you might get an error in the following situations:
- Your API key is invalid or expired.
- You try to publish a package that has an identifier that already exists on the host.
- You make changes to a published package, but you forget to update the version number before you try to publish it again.
The error message typically indicates the source of the problem.
For example, suppose the identifier Contoso.App.Logger.Test exists on nuget.org. If you try to publish a package with that identifier, you get the following error:
Response status code does not indicate success: 403 (The specified API key is invalid, has expired, or does not have permission to access the specified package.).
To address this situation, check the scope, expiration date, and value of your API key. If the key is valid, the error indicates that the package identifier already exists on the host. To overcome the problem, change the package identifier to be unique, rebuild the project, re-create the .nupkg file, and retry the push command.
Manage the published package
When your package is successfully published, you receive a confirmation email. To see the published package, go to nuget.org, select your user name in the upper-right corner, and then select Manage Packages.
Note
It might take a while for your package to be indexed and to appear in search results where others can find it. During that time, your package appears under Unlisted Packages, and the package page shows the following message:
Now that your NuGet package is published at nuget.org, other developers can use it in their projects.
If you create a package that isn't useful (such as this sample package from an empty class library), or if you don't want the package to be visible, you can unlist the package to hide it from search results:
After the package appears under Published Packages on the Manage Packages page, select the pencil icon next to the package listing.
On the next page, select Listing, clear the List in search results checkbox, and then select Save.
The package now appears under Unlisted Packages in Manage Packages and no longer appears in search results.
Note
To avoid your test package being live on nuget.org, you can push to the nuget.org test site at https://int.nugettest.org. Note that packages uploaded to int.nugettest.org might not be preserved.
Add a read-me or another file
You can include a read-me file or other files in your package.
Add a read-me file
To add a read-me file to the package, take the following steps:
Open the project file by selecting Project > Edit Project File.
In the project file, go to the
PropertyGroupelement, and then add aPackageReadmeFilechild element:<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> ... <PackageReadmeFile>readme.md</PackageReadmeFile> ... </PropertyGroup> </Project>Go to the
ItemGroupelement, and then add aNonechild element:<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> ... <PackageReadmeFile>readme.md</PackageReadmeFile> ... </PropertyGroup> <ItemGroup> ... <None Include="readme.md" Pack="true" PackagePath="\" /> ... </ItemGroup> </Project>
In the preceding example, the property specifies a file named readme.md in the project root. After you build, pack, and publish your package, nuget.org displays the contents of the read-me file on the package page. Visual Studio also displays the contents of that file in the Package Manager UI.
For example, the following screenshot shows the read-me file for the HtmlAgilityPack package:
Add other files
To add other files to a package, open the project file by selecting Project > Edit Project File. Then add a Content child element to the ItemGroup element:
<ItemGroup>
<Content Include="other-content.md">
<Pack>true</Pack>
<PackagePath>\</PackagePath>
</Content>
</ItemGroup>
For more information, see Including content in a package.
Related videos
For videos about using NuGet for package management, see .NET Package Management with NuGet for Beginners and NuGet for Beginners.
Related content
To find out how to create a NuGet package with the Visual Studio .NET Framework, see Create a package using the nuget.exe CLI.
For more information about NuGet, see the following articles: