Create and publish a NuGet package using visual studio mac 2019

Hina Ahuja
Globant
Published in
5 min readJan 7, 2022
Photo by HowC#

In .Net, NuGet is a mechanism to share the code which defines how packages for .NET are created, hosted and consumed and provides the tools for each of those roles. NuGet is a package manager which is basically used for reusing the code. A NuGet package is a single ZIP file with the .nupkg extension that contains compiled code (DLLs).

Pre-requisites to create a NuGet:

  1. Install any edition of Visual Studio 2019 from visualstudio.com with a .NET Core related workload.

Create a .net library project:

  1. Open Visual studio
  2. Select File option

3. Select New Solution option.

4. Select .Net standard library template and click next.

5. Target framework should be Standard 2.1 and click next.

6.Specify the name of the project and click create.

Steps to create NuGet package:

  1. Open Visual studio.
  2. Create a .net library project by following above steps
  3. Right click on the project.

4. Select option field from the menu and a window will be open.

5. In the last NuGet package section select build option.

When you check the checkbox it shows the warning to configure the metadata so before creating the package, Metadata needs to be configured.

6. Select Metadata option from the window and you can see Metadata will have two tabs General and Details

7.Select General and give your package a unique identifier and fill out any other desired properties.

Id: is the package Id this is the identifier of the package, it must be unique

Version: is the package version

Author: Set the author’s name, the default value is AssemblyName

Description: Description is the definition of the package what is the intend of the package.

8. Now select Details tab, all the fields are optional except Owners field in details section.

9. Give owner’s name (the default value is Assembly name) and then click on the build option in same window.

You will be able to create the NuGet package by add these details but keep in mind that for publishing a package specifying license url is important. However when you publish your NuGet you will get the warning stating he 'licenseUrl' element will be deprecated. Consider using the 'license' element instead.

To avoid this warning provide LicenseExpression instead <PackageLicenseExpression>MIT</PackageLicenseExpression>

To add the license follow below steps:

12. Right click on the project -> Select Edit Project File Option -> Remove <PackageLicenseUrl> -> and paste <PackageLicenseExpression>MIT</PackageLicenseExpression>

To read about license check this link https://docs.microsoft.com/en-us/nuget/reference/nuspec#licenseurl

13. Now check the create a NuGet package option and close the window.

Generate the package:

14. Select the build option from top menu.

15. Click on the pack option, it will build the solution and pack it as NuGet Package.

16. Now observe the build output window you will the package name with extension .nupkg.

Publish the NuGet

17. To publish a NuGet package go to https://www.nuget.org/

18. Sign in with your account

19. After sign in register your account by giving a unique Username

20. After entering user name, click on Register then below screen will appear.

21. Now right click on the project in Visual studio and select Reveal in Finder option -> go to Bin. -> go to Debug -> select .nupkg file and drag it to the browse option in the above screen.

Your package will be successfully uploaded.

References:

--

--