NuGet is a package manager that delivers compiled source code (DLLs) and other files (scripts and images) related to code. A NuGet package takes the form of a zip file with the extension .nupkg. This makes adding, updating, and removing libraries easy in Visual Studio applications. Using NuGet to install and update packages reduces the manual work of configuring third-party libraries in an application by installing a setup or extracting a zip file and adding the required assemblies to references and files.
The feed link is a URL that is the location of the NuGet package published in the localhost or local directory. You can get a package only through a feed link from the host.
By default, Visual Studio is configured with the public NuGet feed link.
To configure the private feed link or a local path in Visual Studio, follow these steps:
The NuGet Package Manager in Visual Studio on Windows allows you to easily install, uninstall, and update NuGet packages in projects and solutions.
By default, prerelease-versioned packages are not available when searching NuGet. Only stable versions are available. If you want to include prerelease versions in your search, select the Include prerelease option next to the search box.
By default, when installing NuGet packages, corresponding package dependencies will also be installed in your project. To avoid the installation of dependent packages, choose the Ignore Dependencies option in the Dependency behavior drop-down in NuGet Package Manager.
To uninstall the dependency packages of a selected NuGet package, choose the Remove Dependencies option from the NuGet Package Manager.
Package Restore installs the direct dependencies of a project as needed and then installs any dependencies of these packages throughout the entire dependency graph. When the project is opened or compiled, all the added NuGet packages will be restored. Follow these steps to use this feature:
Clear NuGet packages is an action that removes already installed NuGet caches from the cache location. Usually the NuGet packages are installed from the cache location if one exists, otherwise it will be downloaded from the corresponding feed in the cache location.
If you encounter package installation problems or if you want to ensure that you’re installing packages that have been configured locally (your own packages), clear the NuGet cache in the cache location to resolve the issues.
You can clear NuGet by following one of these ways:
The NuGet Package Manager Console uses NuGet PowerShell commands to find, install, uninstall, restore, and update NuGet packages. The console is built into Visual Studio on Windows.
Install a package using the console by entering the following command:
Install-Package <Package Name> -Version <version>
Example:
PM> Install-Package Syncfusion.SfChart.WPF -Version 17.3.0.14
If you want to install a beta (prerelease) NuGet package using the console, include -IncludePrerelease in the command:
Install-Package <Package Name> -Version <version> IncludePrerelease
Example:
PM> Install-Package Syncfusion.SfChart.WPF -Version 17.2.0.28-beta -IncludePrerelease
If you want to install a package without dependencies using the console, use -IgnoreDependencies in the command:
Install-Package <Package Name> -Version <version> IgnoreDependencies
Example:
PM> Install-Package Syncfusion.SfChart.WPF -Version 17.2.0.28-beta -IgnoreDependencies
To uninstall a package from the project through the console, use the following command:
Uninstall-Package <Package Name>
Example:
PM> Uninstall-Package Syncfusion.SfChart.WPF
To remove the dependencies of a selected package when uninstalling it through the console, use -RemoveDependencies in the uninstall command.
Uninstall-Package <Package Name> -Version <Version> -RemoveDependencies
Example:
PM> Uninstall-Package Syncfusion.SfChart.WPF -RemoveDependencies
The Update-Package command is used to upgrade or downgrade an existing package in your project.
Update-Package [Package Name] <string> [-Version] <string> [-IgnoreDependencies]
Example:
PM> Update-Package Syncfusion.SfChart.WPF -Version 17.2.0.40 -ignoreDependencies
To update prerelease (beta) packages, use the following command:
Update-Package [Package Name] <string> [-Version] <string> [-IgnoreDependencies] [-IncludePrerelease]
Example:
PM> Update-Package Syncfusion.SfChart.WPF -Version 17.2.0.40 -ignoreDependencies -IncludePrerelease
The NuGet CLI tool allows you to easily update and restore NuGet packages in projects and solutions. To execute NuGet CLI commands, you must have the nuget.exe file. You can download it from nuget.org.
The NuGet CLI requires a packages.config file for package references. This should be placed in the project location.
Open the command prompt, and then navigate to the directory that contains the project file to execute the NuGet CLI commands.
The install command downloads and installs the package into the project from specified package sources. When installing the package, it is placed in the project’s root directory by default.
Use the following command to install a NuGet package in the packages folder:
nuget install <Package Name> -OutputDirectory <OutputPath>
Example
nuget install Syncfusion.Data.WPF -OutputDirectory D:\Sample
NuGet installs the latest version of a package when using the install command unless you specify the package version. Specify the version in the install command to install a specific version of the package.
nuget install <Package Name> -Version <Version>
Example
nuget install Syncfusion.Tools.windows -Version 17.2.0.40
The uninstall-package command removes a NuGet package from the project.
uninstall-package <Package Name>
Example
uninstall-package Syncfusion.Data.WPF
When uninstalling a NuGet package that depends on other packages, use the -Force command.
uninstall-package <Package Name> -Force
Example
uninstall-package Syncfusion.Data.WPF -Force
To restore the solution with the help of the NuGet CLI, use the restore command. It will restore all the packages available in the package.config.
nuget restore <SolutionFile>
Example:
nuget restore D:\NuGet\NuGetDemo.sln
Restore only adds packages to the disk; it does not change a project’s dependencies. To restore a project’s dependencies, modify packages.config and then use the restore command.
The dotnet CLI allows you to easily install, uninstall, and update NuGet packages in projects and solutions. It runs on Windows, Mac OS X, and Linux.
Open a command prompt, and then navigate to the directory that contains the project file. Use the following dotnet CLI commands to perform the respective operations:
Use the add package command to add a package into the project references:
dotnet add package <Package Name>
Example
dotnet add package Syncfusion.SfGrid.WPF
If a version is not specified, NuGet installs the latest version of the package. You can also use the dotnet add package command to install a specific version of a NuGet package:
dotnet add package <Package Name> <Version>
Example
dotnet add package Syncfusion.SfGrid.WPF 17.2.0.40
The remove package command removes a package reference from a project file:
dotnet remove package <Package Name>
Example
dotnet remove package Syncfusion.SfGrid.WPF
To restore a package, use the dotnet restore command. It restores the project references from the current directory:
dotnet restore [Project|Solution]
Example
dotnet restore D:\NuGetDemo\NuGetDemo.csproj
I hope this blog enriched your knowledge about managing NuGet packages in .NET projects. Try out these different approaches and let us know how they worked out for you in the comments section below.
Syncfusion also makes its components available as NuGet packages on NuGet.org. You can use them when using any Syncfusion components in your projects. Syncfusion has about 1000 components in various platforms such as
If you encounter any issues when using them, please feel free to reach out to us through our support forum, support portal, or feedback portal. We are happy to assist you!