To work with NuGet, as a package consumer or creator, you can use command-line interface (CLI) tools as well as NuGet features in Visual Studio.
The MSBuild CLI also provides the ability to restore and create packages, which is primarily useful on build servers. MSBuild is not a general-purpose tool for working with NuGet.
To create a package, first we need to create .nuspec file. This is a manifest file that uses XML to describe the package. This manifest file is used to build a package and it's also stored in the package after the package is built. To create this .nuspec file, execute the following command in a command prompt.
The default name for the manifest file is Package.nuspec.
<package > <metadata> <id>Package</id> <version>1.0.0</version> <authors>username</authors> <requireLicenseAcceptance>false</requireLicenseAcceptance> <license type="expression">MIT</license> <!-- <icon>icon.png</icon> --> <projectUrl>http://project_url_here_or_delete_this_line/</projectUrl> <description>Package description</description> <releaseNotes>Summary of changes made in this release of the package.</releaseNotes> <copyright>$copyright$</copyright> <tags>Tag1 Tag2</tags> <dependencies> <group targetFramework=".NETStandard2.1"> <dependency id="SampleDependency" version="1.0.0" /> </group> </dependencies> </metadata> </package>
NuGet produces an error if you try to create a package with default values in your
.nuspec file, so you must change the following fields before proceeding.
For packages built for public consumption, you must define Tags property, as tags help others find your package on sources like nuget.org and understand what it does.
You can also add any other elements to the manifest at this time, as described on Manifest Elements from NuGet - snippset.
The elements are described in .nuspec file reference.
The contents of the Nuget package can be defined either by defining a conventional based folder structure relative to the package manifest file or by using a files element in the manifest file. The convention based approach requires the following folder structure:
<package> <metadata> <id>Nuget.Package.Name</id> <version>1.0.0</version> <title>Nuget Package Name</title> <authors>Company Ltd.</authors> <owners>Joe Smith</owners> <license type="expression">MIT</license> <projectUrl>https://www.website.com/project</projectUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>A description of your package</description> <releaseNotes>Initial 1.0.0 release</releaseNotes> <copyright>Copyright 2022 CompanyLtd</copyright> <tags>sample nuget</tags> <dependencies> <group targetFramework=".NETStandard2.0"> </group> </dependencies> <summary> A summary of your package </summary> </metadata> <files> <file src="README.txt" /> <file src="lib\**" target="\lib\netstandard2.0" /> </files> </package>