top of page

LetsDevOps: Setup & Create Nuget Package for Visual Studio Project using Nuget CLI. Setup in CI/CD.


In this article we will learn how to setup and Create Nuget Package using nuget CLI for Visual Studio Project.

What is Nuget

Nuget is open source package manager tool which creates package like Zip file with extension .nupkg. This package can further used to share the code and for deployment. It is developed by Microsoft.



With the help of this packaging we can decide which binaries needs to be created as output package which can be further used for deployment.

We can easily include the package version and other metadata as per the package requirement.

Package Core File --> Manifest File .nuspec

nuspec XML file is package manifest file where you can declare what are the assemblies you need to include in the Package as well as versioning, dependency and other metadata.

All properties can be defined under Metadata.

.nuspec file Basic schema

<package xmlns="">

Setup Nuget Package

Nuget CLI download

Nuget CLI will be required for the creating the nuspec file and further nuget package.

Edit Environment Variable

Make sure the Nuget CLI is downloaded to the Build Agent/Build Machine and reference is added in the environment variable.

Test the Nuget Installed

Run the nuget through CMD and it should return like below.


Create .nuspec File

Nuspec file will help to create the package, hence first we need to generate this file for specific Visual Studio project.

Step 1: Open the Root folder of .sln or csproj file

Step 2: Open the CMD & run below command.

cd <Project Path>
nuget spec

Step 4: Edit the newly created .nuspec file and update the detail as per the your requirement.

you can also include the multiple file and folders as part of the packaging.

Example: In this example I have included the files to be added as part of the package creation

<file src="..\BuildNugetPackage\BuildNugetPackage\bin\Release\**\*.*" target="TargetNugetPackage\bin" />
<file src="bin\*.*" target="TargetNugetPackage\bin" />

Note: I have marked the version as variable since this can be updated on each build but other metadata properties can be also mark as variable and during the runtime it can be updated.

Sample file:

<?xml version="1.0" encoding="utf-8"?>
<package >
    <license type="expression">MIT</license>
    <!-- <icon>icon.png</icon> -->
    <description>Learn to Create Nuget Package</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <tags>Tag1 Tag2</tags>
      <group targetFramework=".NETStandard2.1">
        <dependency id="SampleDependency" version="1.0.0" />
        <!-- Add files from an arbitrary folder that's not necessarily in the project -->
        <file src="..\BuildNugetPackage\BuildNugetPackage\bin\Release\**\*.*" target="TargetNugetPackage\bin" />

Step 5: Build the Project

Now the Project needs to be build so that assembly files will be created.

Step 6: Create the Package

After the successful build now we are ready to create Package.

Run below command through CMD

cd <Project Path>
nuget pack -properties version=1.2.02332 <You can provide your build version>

On successful execution you can see the package is created.

Step 7: Verify the nuget package [.nupkg]

Package will be created like: <Package>.<Version>.nupkg


Publish this Package

This method can be included as part of CI/CD and further used for the Publishing to the Package Management Tools.

Implement this in CI/CD Pipeline

Coming Soon...

bottom of page