web analytics
Creating and Publishing NuGet packages Options
@2021-03-07 08:30:01

Publishing a NuGet Package to nuget.org

Once you've created a package, which is a .nupkg file, you publish it to nuget.org using either the nuget.exe CLI or the dotnet.exe CLI along with an API key acquired from nuget.org.

Acquire your API key
  1. Sign into your nuget.org account or create an account if you don't have one already.
  2. Select your username (on the upper right), then select API Keys.
  3. Select Create, provide a name for your key, select Select Scopes > Push. Under API Key, enter * for Glob pattern, then select Create. (See below for more about scopes.)

.NET Standard 

Once the key is created, select Copy to retrieve the access key you need in the CLI,

.NET Standard


Save your key in a secure location because you cannot copy the key again later on. 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 via the CLI.

Publish with nuget push

Push your package to NuGet Gallery using the following command:

nuget push YourPackage.nupkg  <your_API_key> -Source https://api.nuget.org/v3/index.json


@2021-03-07 12:34:25

NuGet Package Explorer

NuGet Package Explorer is an application that makes it easy to create and explore NuGet packages. 

Creating a Package

1. Launch NPE and select File > New (Ctrl-N), or select Create a new package from the Common tasks dialog when Package Explorer starts:

2. Select Edit > Edit Package Metadata (Ctrl-K) to open the editor for the underlying .nuspec file. Details for the metadata can be found in the nuspec reference.

3. Open the files you want to include in the package in Windows explorer, then drag them into the Package contents pane of Package Explorer. Package Explorer will attempt to infer where the content belongs and prompt you to place it in the correct directory within the package. (You can also explicitly add specific folders using the Content menu.)

For example, if you drag an assembly into the Package contents window, it will prompt you to place the assembly in the lib folder:

4. Save your package with File > Save (Ctrl-S).

5. If you have a code signing certificate, sign your package with File > Sign and Save As.

Publishing a Package

1. Create a free account on nuget.org, or log in if you already have one. When creating a new account, you'll receive a confirmation email. You must confirm the account before you can upload a package.

2. Once logged in, click your username (on the upper right) to navigate to your account settings.

3. Under API Key, click copy to clipboard to retrieve the API key you'll need in the next step.

4. Assuming your package is loaded in Package Explorer, select File > Publish (Ctrl-P) to bring up the Publish Package dialog.

5. Paste your API key into Publish key and click Publish to push the package to nuget.org.

6. In your profile on nuget.org, click Manage my Packages to see the one that you just published; you'll also receive a confirmation email. Note that it might take a while for your package to be indexed and appear in search results, during which time you'll see a message that the package hasn't yet been indexed.

@2021-03-20 13:48:51

Publishing a NuGet Package to Azure Artifacts

Publish NuGet packages to a feed in Azure Artifacts to share them with your team and your organization.

1.Go to your feed, or create a feed if you haven't by clicking Create feed. This feed will be a collection of NuGet packages available to users within the organization and will sit alongside the public NuGet feed as a peer. 

2.Select Connect to feed:

Connect to feed button on the upper right of the page

3.Select NuGet.exe under the NuGet header.

4.If you installed NuGet, and you have at least one edition of Visual Studio on your machine, you can move to the next step. Otherwise:

  • Select Get the tools in the upper-right corner.
  • Download the latest NuGet version if you haven't yet.
  • Download and install the credential provider (if you don't have any Visual Studio edition).

5.Copy the xml code snippet in the Project setup section and add/create a nuget.config file for your project. Place your file in the same folder as your .csproj or .sln file.

6.To publish your package to your feed, run the command in the Publish packages section in an elevated PowerShell window. Don't forget to specify your local package path (for example: ..\HelloWorld\NuGetPackage\HelloWorld1.0.0.nupkg).

NuGet publish instructions in Connect to feed dialog box

@2021-03-20 18:40:42

Creating your own NuGet Server

Having our own NuGet Server can help us to generate a package with each version of the library and have it available for each project and member of the development team. By following the steps below you can create our own NuGet Server, make a package, publish it and install it in any project.

Creating NuGet Server

First we need to create an Empty Web Application and add the NuGet.Server package.

1.Creating an empty web application for a NuGet server.

2.Adding the NuGet.Server package to the project.

3. Running the project we will have the NuGet Server working.

Publishing the NuGet Server in IIS

1.Creating the website on IIS that hosts the Nuget Server

The first thing you must do is create a Website, for that, after opening the IIS administration window, we right-click on Sites and then Add Website… which will open a window to indicate the details of the new Website, as the name, the path where the files will be and the port. This is the basic configuration.


2. Publishing our NuGet Server in IIS

Now we are going to publish the project where we have our NuGet Server in the website that we have just created: basically we right click on the name of the project and then on Publish… this will open a window where we must select the target, and indicate the destination site data, as seen in step 2 of the image, save the information and then click on Pusblish.

3. Configuring the apiKey in NuGetServer

It is also necessary to configure an apiKkey in the Application Settings (web.config), which should be indicated when publishing a package. In this case I put the value 809.

With this, our server is ready to receive and serve NuGet packages.

Creating and publishing a package

We are almost ready to create our first package, which we can version and have it available from our NuGet Server.

1. Install NuGet.CommandLine

First we need to install the NuGet.CommandLine package in the project we want to create a package, in my case create a test project called MyLibrary. The NuGet.CommandLine will allow us to execute NuGet commands in our project.

2. Creating a package using NuGet Pack

NuGet Pack is the command that creates the package that we want to publish to the server, that is, a file with extension .nupkg, of the project that we indicate. This command can be executed in the Package Manager Console and takes as an argument the path of the project and the configuration in which we want it to be created, in this case: release, that is, ready to be used in production.

The description, the author, the company, version and other information of the package must be indicated in the properties of the project. Once this is done we can execute the command:

NuGet Pack .\MyLibrary\MyLibrary.csproj -Properties Configuration=release

after run the command, the package MyLibrary.1.0.0.nupkg will be created in the project’s solution folder.

3. Publish the package using NuGet Push

NuGet Push is the command that will allow us to publish our package to NuGet Server, we have to indicate the package path, the server url and the apiKey that we configured previously.

NuGet Push .\MyLibrary.1.0.0.nupkg -Source http://localhost:2019/nuget -ApiKey 809

Installing the NuGet Package

Since the package is our Nuget Server we can install it, but first we must add it as a source of packages in the NuGet Package Manager, for that we right-click on a project, then click Manage NuGet Package… and add the url of our NuGet Server as a source of packages.

With this we can install our package in any project.

You must Sign In to comment on this topic.

© 2021 Digcode.com