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

The simplest way to install a package is using the .NET CLI:

Terminal window
dotnet add package PackageName

For example, to install CleanArchSharp:

Terminal window
dotnet add package CleanArchSharp

Using Package Manager Console

In Visual Studio, you can use the Package Manager Console:

Terminal window
Install-Package PackageName

Using Visual Studio

  1. Right-click on your project in Solution Explorer
  2. Select “Manage NuGet Packages”
  3. Search for the package name
  4. Click “Install”

Specifying Version

To install a specific version:

Terminal window
dotnet add package PackageName --version 1.0.0

Verifying 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:

Terminal window
dotnet add package PackageName

To update to a specific version:

Terminal window
dotnet add package PackageName --version 2.0.0

Removing Packages

To remove a package:

Terminal window
dotnet remove package PackageName

Next Steps

After installing a package:

  1. Check the package’s documentation for usage examples
  2. Add any required configuration to appsettings.json or Program.cs
  3. Register services in the dependency injection container if needed

Troubleshooting

Package Not Found

If you get a “Package not found” error:

  1. Check the package name spelling
  2. Verify the package exists on NuGet.org
  3. Ensure your NuGet sources are configured correctly

Version Conflicts

If you encounter version conflicts:

Terminal window
dotnet list package --outdated
dotnet add package PackageName

Restore Issues

If packages fail to restore:

Terminal window
dotnet restore

Or clear the NuGet cache:

Terminal window
dotnet nuget locals all --clear