What is nuspec file and how to create it

In this article, we understand what is .nuspec file and how to generate a .nuspec file using PowerShell. So let’s understand more about the .nuspec file and how the .nuspec file looks.


nuspec file


What is the .nuspec file?


A .nuspec file is an XML-formatted file that is used to define the metadata for a .NET dependency, which is a reusable piece of code that can be shared between multiple projects. The .nuspec file is used by the NuGet package manager to build and publish a package and this Nuget package can be published in GitHub and later you can use the same in any of the projects as project dependencies.


It includes information about the package, such as its name, version, author, and description. It can also specify any dependencies that the package has on other packages, and the .nuspec file can include additional files that should be included in the package.


Here is an example of how the .nuspec file looks-


<?xml version="1.0"?>
<package >
    <title>My Package</title>
    <authors>Author Name</authors>
    <owners>Author Name</owners>
    <description>A description of my package</description>


How to create a .nuspec file using PowerShell

Open the PowerShell editor and run the below command to generate the .nuspec file –

nuget spec


They will generate the .nuspec file in the current working directory and its name is like package id and version 1.0.0.

We can specify additional options to customize the .nuspec file. For example- you can use the -OutputDirectory option to specify a different location for the .nuspec file, and the -Version option to specify a different package version.


nuget spec -OutputDirectory C:\nuspecfiles -Version 2.0.0


This would generate a .nuspec file in the “C:\nuspecfiles” folder, with a package version of 2.0.0.



I hope now you have some insight into the .nuspec file and how you can generate a .nuspec file using PowerShell. To know more about the NuGet spec and all its options use the “nuget help spec” command.