Press "Enter" to skip to content

Creating nuget package

vpandzic 0

First step to create nuget package is to create .nuspec  file. If you are familiar with npm then it is even easier for you because I will make comparison with npm along the way. In npm you would do npm init to create package.json file, and it will walk you through some settings you will need in package.json. To be able to do that you would need npm in your path. Similary, if you do nuget spec  you will probably get this error:

‘nuget’ is not recognized as an internal or external command,
operable program or batch file.

Keep in mind there is also nuget init  command but it works completely different then in npm world. You should download nuget command line tool and put it somewhere on your hard drive and put that location in your PATH system environment variable. You can download nuget.exe from this website Don’t forget to close and open command line prompt again after putting nuget inside system environment variable.

Then type again:

nuget spec

Nuget command line (at least newest stable version in time of writing – version 2.8.5 will

not walk you through but instead it will just create file YourProjectName.nuspec. .nuspec  is xml file containing metadata about your project like version, title,description and similar. You should then go inside that file, populate it with your own data, and inside command line do:

nuget pack


Creating nuspec file , to create nuget package

There are few errors that could happen. If you are just trying on some newly created project how to create nuget package and you didn’t build it yet you will get appropriate error message. If you deleted some required metadata elements you will get errors. List of required elements include: id, version, authors, description and title.

In case of success .nupkg  file will be created.

A .nupkg  file is just a ZIP file with a different extension. You can also examine package contents, then, by changing .nupkg  to .zip , but remember to restore the extension before uploading a package to

So, in summary this is what you have to do:

  1. Download nuget command line, save it somewhere, and put that folder location inside system PATH environment variable (required once)
  2. In command line, while inside project location type nuget spec to create .nuspec  file. (or create it manually and put at least id,title,version,description, and authors element). See image above.
  3. Pack it with nuget pack  command to create .nupkg  file.


Leave a Reply

Your email address will not be published. Required fields are marked *