Installation Guide
This guide covers the different ways to install NuGet packages in your .NET projects.
Prerequisites
Before installing any package, ensure you have:
- .NET SDK 6.0 or later installed
- A .NET project (Console, Web API, Blazor, etc.)
- Access to NuGet.org
Installation Methods
Using .NET CLI (Recommended)
The simplest way to install a package is using the .NET CLI:
dotnet add package PackageNameFor example, to install CleanArchSharp:
dotnet add package CleanArchSharpUsing Package Manager Console
In Visual Studio, you can use the Package Manager Console:
Install-Package PackageNameUsing Visual Studio
- Right-click on your project in Solution Explorer
- Select “Manage NuGet Packages”
- Search for the package name
- Click “Install”
Specifying Version
To install a specific version:
dotnet add package PackageName --version 1.0.0Verifying Installation
After installation, verify the package is added to your project by checking the .csproj file:
<ItemGroup> <PackageReference Include="PackageName" Version="1.0.0" /></ItemGroup>Always check the package documentation for any additional setup or configuration required after installation.
Make sure your project’s target framework is compatible with the package. Check the package’s NuGet page for supported frameworks.
Updating Packages
To update a package to the latest version:
dotnet add package PackageNameTo update to a specific version:
dotnet add package PackageName --version 2.0.0Removing Packages
To remove a package:
dotnet remove package PackageNameNext Steps
After installing a package:
- Check the package’s documentation for usage examples
- Add any required configuration to
appsettings.jsonorProgram.cs - Register services in the dependency injection container if needed
Troubleshooting
Package Not Found
If you get a “Package not found” error:
- Check the package name spelling
- Verify the package exists on NuGet.org
- Ensure your NuGet sources are configured correctly
Version Conflicts
If you encounter version conflicts:
dotnet list package --outdateddotnet add package PackageNameRestore Issues
If packages fail to restore:
dotnet restoreOr clear the NuGet cache:
dotnet nuget locals all --clear