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.
Once the key is created, select Copy to retrieve the access key you need in the CLI,
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.
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
NuGet Package Explorer is an application that makes it easy to create and explore NuGet packages.
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.
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.
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:
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:
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).
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.
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.
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.
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
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.
© 2021 Digcode.com