Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

How to Create NuGet Packages with nuget.exe (Assembly, .nuspec, and .csproj Methods)

Creating a NuGet package is a core skill for .NET and DevOps engineers who need to distribute internal libraries, scripts, or reusable project assets. This guide explains the three packaging approaches shown in the original tutorial, when each one fits best, and the exact commands and manifest structure you need to produce a .nupkg artifact.

Originally published on 2015-11-21; fully revised and updated.

create-a-package-in-nuget

Choose the right packaging method

The original tutorial presents three ways to create packages with nuget.exe. In practice, your starting point (compiled DLL, folder layout, or project file) determines which workflow is fastest.

MethodBest forPrimary command pathNotes
From an assemblyYou already have a compiled DLL and want a quick packagenuget spec MyAssembly.dll then nuget pack MyAssembly.nuspecSimple and fast; metadata comes from assembly and edited .nuspec.
From a convention-based folder + nuspecPackages that include content, scripts, tools, or build assetsnuget spec then nuget pack YourPackage.nuspecMost flexible for non-DLL assets and custom folder structures.
From a Visual Studio projectProject-centric packaging with token replacement and optional referenced projectsnuget spec then nuget pack MyProject.csprojUses project metadata tokens like $id$ and $version$.

NuGet packaging workflow

All three methods follow the same high-level flow: generate or prepare a manifest, verify package content, build the package, and then publish to your feed.

flowchart TD
    A[Start packaging] --> B{What do you have?}
    B --> C[Compiled assembly]
    B --> D[Folder layout and files]
    B --> E[Project file]
    C --> F[Generate nuspec from dll]
    D --> G[Generate or edit nuspec]
    E --> H[Generate tokenized nuspec]
    F --> I[Edit metadata and dependencies]
    G --> I
    H --> I
    I --> J[Run nuget pack]
    J --> K[Validate nupkg contents]
    K --> L[Publish to repository]

Method 1: Create a package from an existing assembly

Use this when you already have a compiled assembly and want NuGet to scaffold a .nuspec from assembly metadata.

nuget spec MyAssembly.dll
nuget pack MyAssembly.nuspecCode language: CSS (css)

After generating the .nuspec, update metadata fields (ID, version, description, dependencies) before packing.

Method 2: Create a package from a convention-based directory and nuspec

This method is ideal when the package includes more than assemblies, such as content files, scripts, and build artifacts.

FolderPurpose in package
libAssemblies to be added as references on install.
toolsPowerShell scripts and executables accessible from Package Manager Console.
contentFiles copied into the target application structure.
buildMSBuild targets files applied to consuming projects.

Step 1: Generate the manifest

nuget spec

This creates a .nuspec file you can edit. Example manifest from the original tutorial:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>MyPackageId</id>
    <version>1.0</version>
    <authors>philha</authors>
    <owners>philha</owners>
    <licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
    <projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
    <iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package description</description>
    <tags>Tag1 Tag2</tags>
    <dependencies>
      <dependency id="SampleDependency" version="1.0" />
    </dependencies>
  </metadata>
</package>Code language: HTML, XML (xml)

Step 2: Lay out package content and build

mkdir lib
mkdir tools
mkdir content
mkdir content\controllers
copy ..\src\SomeController.cs content\controllers
copy ..\src\MyLibrary.dll lib
copy ..\src\SomePowershellScript.ps1 tools
nuget pack YourPackage.nuspecCode language: CSS (css)

Method 3: Create a package from a Visual Studio project

For simple project-based packaging, run commands in the folder containing the .csproj (or .vbproj) file. NuGet creates a tokenized .nuspec and replaces tokens during packing when you pack the project file.

nuget spec
nuget pack MyProject.csprojCode language: CSS (css)

Supported replacement tokens highlighted in the original article:

TokenSource
$id$Assembly name
$version$Assembly version from assembly attributes
$author$Company from assembly attributes
$description$Description from assembly attributes

You can also include additional files through a <files> section in the .nuspec:

<files>
  <file src="..\..\SomeRoot\**\*.*" target="" />
</files>Code language: HTML, XML (xml)

Referenced projects can be included recursively with -IncludeReferencedProjects, and build configuration can be selected with -Prop:

nuget pack A.csproj -IncludeReferencedProjects
nuget pack MyProject.csproj -Prop Configuration=Release

Official references

Common pitfalls

  • Packing the .nuspec instead of the project file when you expect token replacement from project metadata.
  • Using a folder layout that does not match NuGet conventions, causing files not to land where consumers expect.
  • Forgetting to review dependency versions in the generated .nuspec before publishing.
  • Mixing Debug and Release artifacts unintentionally; use -Prop Configuration=Release when needed.
  • Assuming package creation and repository hosting are the same step; package creation is separate from publishing to a feed.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Top 10 AI Influencer Marketing Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI influencer marketing tools have become indispensable for brands navigating the dynamic world of social media marketing. These platforms leverage artificial intelligence to streamline…

Read More

Top 10 Digital Asset Management (DAM) Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, managing digital assets has become more important than ever. As organizations continue to create, store, and manage vast quantities of digital content—whether images, videos,…

Read More

The Main Challenges of Metaverse Game Development

The news about tech giants investing in metaverse development ignited a lot of discussions about its potential use cases. GameDev has turned up at the forefront of…

Read More

Top 10 AI Data Integration Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI data integration tools are pivotal for businesses navigating the complexities of modern data ecosystems. These tools combine artificial intelligence with data integration processes…

Read More

Top 10 Presentation Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, creating engaging and impactful presentations is more than just slides with bullet points—it’s about telling a story, conveying ideas visually, and keeping your audience…

Read More

Top 10 AI Ad Copy Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI ad copy tools have become indispensable for marketers, businesses, and content creators aiming to craft compelling, high-converting advertisements at scale. These tools leverage…

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Puja kushwaha
Puja kushwaha
13 days ago

Creating a NuGet package is easier when you plan its structure and metadata before packing it. Use clear package names, meaningful version numbers, and accurate dependency details to help other developers use it safely. Testing the package in a clean project can catch missing files or references early. It is also worth adding a README with setup steps and examples. These small checks make a package easier to share, update, and maintain.

1
0
Would love your thoughts, please comment.x
()
x