Installing NuGet Packages: A Binger’s Guide

This post walks you through the different ways to install NuGet packages using Visual Studio, the .NET CLI, and the NuGet Package Manager Console.

Installing NuGet Packages: A Binger’s Guide

Getting Started

NuGet is the official package manager for .NET, allowing you to install libraries and tools with just a few commands or clicks, whether you're building a desktop app, a web application, or a cloud-based service.

What Is NuGet

NuGet is the official package manager for .NET like npm for JavaScript or pip for Python. It hosts thousands of reusable libraries—so you don’t have to reinvent the wheel every time you need JSON serialization or dependency injection.

What Is a NuGet Package

A NuGet package is a single ZIP file with a .nupkg extension that contains compiled code (DLLs), metadata, and other files related to a reusable library or tool. These packages are hosted on nuget.org , the central package repository.

Install a NuGet Package

Installing NuGet packages is a fundamental skill for .NET developers. Whether you're working in Visual Studio or using the command line, NuGet simplifies dependency management and allows you to focus on writing code rather than reinventing the wheel. Below are the details on how to install a NuGet package in various methods.

Installing via Visual Studio (GUI)
This method is best for those developer who is bigner and loves GUI.
  1. Right-click on your project in the Solution Explorer
  2. Select Manage NuGet Packages
  3. Go to the Browse tab
  4. Type the name of the package (e.g., Newtonsoft.Json)
  5. Click Install
  6. Accept the license agreement (you always do it blindly anyway)

Install NuGet(PowerShell)
To install a NuGet package using PowerShell, you typically use either:
  1. The Package Manager Console inside Visual Studio, or
  2. The nuget.exe CLI or dotnet CLI from an external PowerShell session.
Below are the different ways to install a NuGet package via PowerShell:

Using the Package Manager Console in Visual Studio
This is the most common method for .NET Framework projects.
  1. Open Tools > NuGet Package Manager > Package Manager Console
  2. Type the following command:
       Install-Package <PackageName>

      Example:
       Install-Package Dapper
      This command pulls the latest stable version from nuget.org and installs it into the selected project. You can also specify versions:
       Install-Package Dapper -Version 2.0.123

Using nuget.exe CLI in PowerShell (for manual workflows)
First, download nuget.exe from nuget.org/downloads and place it in your system PATH.
Then use:
 Install-Package <PackageName>

Example:
 Install-Package Dapper -Version 2.0.123
This installs the package into a packages/ folder in your current directory.

Using the dotnet CLI in PowerShell (.NET Core / .NET 5+ projects)
This is the preferred method for modern SDK-style projects.
 Install-Package <PackageName>

Example:
 dotnet add package Newtonsoft.Json
You can also specify a version:
 dotnet add package Newtonsoft.Json --version 13.0.3

Manually Editing .csproj

Sometimes you’re working in a Frankenstein environment or dealing with automation scripts. Here’s how to go caveman mode:
 <ItemGroup>  
  <PackageReference Include="Polly" Version="7.2.3" />  
 </ItemGroup>  

Then run:
 dotnet restore

Not ideal for bingers, but good to know.

Best Practices

  1. Check Compatibility: Some packages only support specific .NET versions.
  2. Always use exact versions in production apps for stability.
  3. Use --prerelease with CLI to grab pre-release packages
  4. Avoid unnecessary packages to reduce bloat.
  5. Keep packages up to date with:
       dotnet list package --outdated
  6. Use a lock file (packages.lock.json) in CI environments to ensure deterministic builds.
  7. Clear NuGet cache if you run into strange issues:
       dotnet list package --outdated

Troubleshooting

  • Package not found: Check spelling or package source (nuget.org?)
  • Version conflict: Try a compatible version or update dependencies
  • Restore failed: Run dotnet restore manually or check network or Delete bin and obj folders, then run dotnet restore again.

Summary

Installing NuGet packages isn’t rocket science, but when you're deep in a project and every second counts, you want the quickest route. Whether you're navigating GUIs or firing off terminal commands, the tools are ready when you are.

Thanks

Kailash Chandra Behera

I am an IT professional with over 13 years of experience in the full software development life cycle for Windows, services, and web-based applications using Microsoft .NET technologies.

Previous Post Next Post

نموذج الاتصال