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.- Right-click on your project in the Solution Explorer
- Select Manage NuGet Packages
- Go to the Browse tab
- Type the name of the package (e.g.,
Newtonsoft.Json
) - Click Install
- Accept the license agreement (you always do it blindly anyway)
Install NuGet(PowerShell)
To install a NuGet package using PowerShell, you typically use either:- The Package Manager Console inside Visual Studio, or
- The
nuget.exe
CLI or dotnet CLI from an external PowerShell session.
Using the Package Manager Console in Visual Studio
This is the most common method for .NET Framework projects.- Open Tools > NuGet Package Manager > Package Manager Console
- Type the following command:
Example:Install-Package <PackageName>
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
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
- Check Compatibility: Some packages only support specific .NET versions.
- Always use exact versions in production apps for stability.
- Use
--prerelease
with CLI to grab pre-release packages - Avoid unnecessary packages to reduce bloat.
- Keep packages up to date with:
dotnet list package --outdated
- Use a lock file (
packages.lock.json
) in CI environments to ensure deterministic builds. - 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 Deletebin
andobj
folders, then rundotnet 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