Use Nuget Package Restore To Download Them UPDATED
Use Nuget Package Restore To Download Them
This browser is no longer supported.
Upgrade to Microsoft Border to take advantage of the latest features, security updates, and technical support.
Restore packages using Parcel Restore
To promote a cleaner development environment and to reduce repository size, NuGet Package Restore installs all of a project's dependencies listed in either the project file or packages.config
. The .NET Core 2.0+ dotnet build
and dotnet run
commands practise an automated package restore. Visual Studio tin restore packages automatically when it builds a project, and yous tin restore packages at whatever time through Visual Studio, nuget restore
, dotnet restore
, and xbuild on Mono.
Package Restore makes certain that all a projection's dependencies are available, without having to shop them in source control. To configure your source control repository to exclude the package binaries, run into Packages and source command.
Package Restore overview
Packet Restore showtime installs the straight dependencies of a project equally needed, and then installs whatever dependencies of those packages throughout the unabridged dependency graph.
If a package isn't already installed, NuGet first attempts to retrieve it from the enshroud. If the packet isn't in the cache, NuGet tries to download the parcel from all enabled sources in the list at Tools > Options > NuGet Package Director > Package Sources in Visual Studio. During restore, NuGet ignores the order of package sources, and uses the package from whichever source is first to respond to requests. For more information about how NuGet behaves, see Common NuGet configurations.
Note
NuGet doesn't point a failure to restore a parcel until all the sources have been checked. At that fourth dimension, NuGet reports a failure for only the last source in the list. The error implies that the package wasn't present on any of the other sources, even though errors aren't shown for each of those sources individually.
Restore packages
Package Restore tries to install all packet dependencies to the correct state matching the packet references in your projection file (.csproj) or your packages.config file. (In Visual Studio, the references appear in Solution Explorer under the Dependencies \ NuGet or the References node.)
-
If the packet references in your project file are correct, use your preferred tool to restore packages.
- Visual Studio (automatic restore or transmission restore)
- dotnet CLI
- nuget.exe CLI
- MSBuild
- Azure Pipelines
- Azure DevOps Server
If the package references in your project file (.csproj) or your packages.config file are incorrect (they do non lucifer your desired country following Parcel Restore), then y'all need to either install or update packages instead.
For projects using PackageReference, afterward a successful restore, the package should be present in the global-packages folder and the
obj/project.assets.json
file is recreated. For projects usingpackages.config
, the bundle should appear in the project'spackages
folder. The project should now build successfully. -
After running Packet Restore, if you however feel missing packages or bundle-related errors (such as error icons in Solution Explorer in Visual Studio), yous may need to follow instructions described in Troubleshooting Bundle Restore errors or, alternatively, reinstall and update packages.
In Visual Studio, the Package Director Panel provides several flexible options for reinstalling packages. Meet Using Package-Update.
Restore using Visual Studio
In Visual Studio on Windows, either:
-
Restore packages automatically, or
-
Restore packages manually
Restore packages automatically using Visual Studio
Bundle Restore happens automatically when you create a project from a template or build a project, discipline to the options in Enable and disable package restore. In NuGet iv.0+, restore as well happens automatically when you make changes to a SDK-style projection (typically a .Cyberspace Core or .Net Standard project).
-
Enable automatic package restore by choosing Tools > Options > NuGet Package Manager, and and so selecting Automatically check for missing packages during build in Visual Studio under Packet Restore.
For non-SDK-style projects, y'all first need to select Allow NuGet to download missing packages to enable the automatic restore option.
-
Build the projection.
If 1 or more than individual packages still aren't installed properly, Solution Explorer shows an mistake icon. Right-click and select Manage NuGet Packages, and use Parcel Manager to uninstall and reinstall the affected packages. For more information, run into Reinstall and update packages
If you see the error "This project references NuGet package(s) that are missing on this estimator," or "I or more NuGet packages demand to be restored merely couldn't exist because consent has not been granted," enable automatic restore. For older projects, also see Migrate to automatic package restore. Also run across Package Restore troubleshooting.
Restore packages manually using Visual Studio
-
Enable package restore past choosing Tools > Options > NuGet Packet Manager. Under Bundle Restore options, select Allow NuGet to download missing packages.
-
In Solution Explorer, right click the solution and select Restore NuGet Packages.
If i or more individual packages all the same aren't installed properly, Solution Explorer shows an error icon. Right-click and select Manage NuGet Packages, and then use Package Director to uninstall and reinstall the affected packages. For more information, see Reinstall and update packages
If you come across the mistake "This projection references NuGet package(s) that are missing on this calculator," or "1 or more than NuGet packages demand to be restored simply couldn't be because consent has not been granted," enable automatic restore. For older projects, besides run across Migrate to automatic parcel restore. Besides run across Package Restore troubleshooting.
Enable and disable package restore in Visual Studio
In Visual Studio, you lot control Packet Restore primarily through Tools > Options > NuGet Package Director:
-
Let NuGet to download missing packages controls all forms of package restore past irresolute the
packageRestore/enabled
setting in the packageRestore section of theNuGet.Config
file, at%AppData%\NuGet\
on Windows, or~/.nuget/NuGet/
on Mac/Linux. This setting also enables the Restore NuGet Packages command on the solution'south context menu in Visual Studio, .<configuration> <packageRestore> <!-- The 'enabled' fundamental is True when the "Allow NuGet to download missing packages" checkbox is set. Clearing the box sets this to Fake, disabling command-line, automatic, and MSBuild-integrated restore. --> <add together cardinal="enabled" value="Truthful" /> </packageRestore> </configuration>
Note
To globally override the
packageRestore/enabled
setting, set the environs variable EnableNuGetPackageRestore with a value of Truthful or False before launching Visual Studio or starting a build. -
Automatically check for missing packages during build in Visual Studio controls automated restore by changing the
packageRestore/automatic
setting in the packageRestore section of theNuGet.Config
file. When this pick is gear up to True, running a build from Visual Studio automatically restores any missing packages. This setting doesn't touch on builds run from the MSBuild command line.... <configuration> <packageRestore> <!-- The 'automatic' key is set up to Truthful when the "Automatically check for missing packages during build in Visual Studio" checkbox is set up. Immigration the box sets this to Fake and disables automated restore. --> <add together fundamental="automated" value="True" /> </packageRestore> </configuration>
To enable or disable Package Restore for all users on a reckoner, a developer or company can add the configuration settings to the global nuget.config
file. The global nuget.config
is in Windows at %ProgramData%\NuGet\Config
, sometimes under a specific \{IDE}\{Version}\{SKU}\
Visual Studio folder, or in Mac/Linux at ~/.local/share
. Individual users can so selectively enable restore equally needed on a projection level. For more details on how NuGet prioritizes multiple config files, encounter Common NuGet configurations.
Important
If you lot edit the packageRestore
settings directly in nuget.config
, restart Visual Studio, so that the Options dialog box shows the current values.
Choose default parcel management format
NuGet has two formats in which a projection may utilize packages: PackageReference
and packages.config
. The default format tin can be selected from the drop-downwardly under the Package Management heading. An option to be prompted when the first package is installed in a project is as well available.
Note
If a project does not back up both package management formats, the bundle management format used will be the i that's uniform with the projection, and therefore may non be the default gear up in the options. Additionally, NuGet will non prompt for choice on get-go parcel installation, fifty-fifty if the selection is selected in the options window.
If Parcel Manager Console is used to install the first parcel in a project, NuGet will non prompt for format choice, even if the option is selected in the options window.
Restore using the dotnet CLI
Use the dotnet restore control, which restores packages listed in the project file (see PackageReference). With .Net Core ii.0 and afterward, restore is done automatically with dotnet build
and dotnet run
. Every bit of NuGet 4.0, this runs the aforementioned code as nuget restore
.
Every bit with the other dotnet
CLI commands, showtime open a control line and switch to the directory that contains your project file.
To restore a package using dotnet restore
:
dotnet restore
Important
To add together a missing package reference to the project file, utilise dotnet add package, which also runs the restore
control.
Restore using the nuget.exe CLI
Utilize the restore control, which downloads and installs any packages missing from the packages binder.
For projects migrated to PackageReference, use msbuild -t:restore to restore packages instead.
restore
only adds packages to disk but does not alter a project's dependencies. To restore projection dependencies, alter packages.config
, then use the restore
command.
As with the other nuget.exe
CLI commands, showtime open a command line and switch to the directory that contains your project file.
To restore a package using restore
:
nuget restore MySolution.sln
Of import
The restore
command does not modify a project file or packages.config. To add a dependency, either add together a package through the Package Manager UI or Console in Visual Studio, or modify packages.config and and so run either install
or restore
.
Restore using MSBuild
Use the msbuild -t:restore command to restore packages listed in the project file (run across PackageReference) and starting with MSBuild sixteen.five+, packages.config
projects.
This control is available just in NuGet 4.x+ and MSBuild xv.i+, which are included with Visual Studio 2017 and higher versions. Starting with MSBuild 16.5+, this command tin can also restore packages.config
based projects when run with -p:RestorePackagesConfig=true
.
-
Open up a Developer control prompt (In the Search box, type Developer command prompt).
You typically want to starting time the Programmer Control Prompt for Visual Studio from the First menu, every bit information technology volition be configured with all the necessary paths for MSBuild.
-
Switch to the folder containing the projection file and type the following command.
# Uses the project file in the electric current binder past default msbuild -t:restore
-
Type the following command to rebuild the project.
msbuild
Brand sure that the MSBuild output indicates that the build completed successfully.
# Will restore the projection, then build, since build is the default target. msbuild -restore
Restore using Azure Pipelines
When you create a build definition in Azure Pipelines, include the NuGet restore or .NET Cadre restore job in the definition earlier any build tasks. Some build templates include the restore task past default.
Restore using Azure DevOps Server
Azure DevOps Server and TFS 2013 and later automatically restore packages during build, if y'all're using a TFS 2013 or later Team Build template. For earlier TFS versions, you tin include a build footstep to run a command-line restore option, or optionally migrate the build template to a later version. For more information, see Prepare upwardly package restore with Team Foundation Build.
Constrain package versions with restore
When NuGet restores packages through whatsoever method, it honors whatsoever constraints you specified in packages.config
or the project file:
-
In
packages.config
, you can specify a version range in theallowedVersion
property of the dependency. See Constrain upgrade versions for more than data. For example:<package id="Newtonsoft.json" version="6.0.iv" allowedVersions="[six,seven)" />
-
In a projection file, yous can use PackageReference to specify a dependency'due south range directly. For example:
<PackageReference Include="Newtonsoft.json" Version="[6, 7)" />
In all cases, apply the notation described in Package versioning.
Force restore from bundle sources
By default, NuGet restore operations use packages from the global-packages and http-cache folders, which are described in Manage the global packages and cache folders.
To avert using the global-packages folder, do ane of the following:
- Clear the folder using
nuget locals global-packages -clear
ordotnet nuget locals global-packages --clear
. - Temporarily change the location of the global-packages folder before the restore operation, using one of the following methods:
- Prepare the NUGET_PACKAGES surround variable to a different binder.
- Create a
NuGet.Config
file that setsglobalPackagesFolder
(if using PackageReference) orrepositoryPath
(if usingpackages.config
) to a different binder. For more information, meet configuration settings. - MSBuild only: Specify a dissimilar binder with the
RestorePackagesPath
holding.
To avoid using the enshroud for HTTP sources, do one of the following:
- Apply the
-NoCache
option withnuget restore
, or the--no-cache
choice withdotnet restore
. These options don't affect restore operations through the Visual Studio Package Managing director or console. - Clear the cache using
nuget locals http-enshroud -clear
ordotnet nuget locals http-cache --articulate
. - Temporarily prepare the NUGET_HTTP_CACHE_PATH environment variable to a dissimilar folder.
Migrate to automatic parcel restore (Visual Studio)
For NuGet two.six and earlier, an MSBuild-integrated bundle restore was previously supported but that is no longer true. (It was typically enabled by right-clicking a solution in Visual Studio and selecting Enable NuGet Package Restore). If your project uses the deprecated MSBuild-integrated package restore, please migrate to automatic bundle restore.
Projects that use MSBuild-Integrated bundle restore typically contain a .nuget folder with three files: NuGet.config, nuget.exe, and NuGet.targets. The presence of a NuGet.targets file determines whether NuGet volition continue to use the MSBuild-integrated arroyo, so this file must be removed during the migration.
To drift to automatic package restore:
- Close Visual Studio.
- Delete .nuget/nuget.exe and .nuget/NuGet.targets.
- For each project file, remove the
<RestorePackages>
chemical element and remove any reference to NuGet.targets.
To exam the automatic package restore:
-
Remove the packages binder from the solution.
-
Open the solution in Visual Studio and beginning a build.
Automatic parcel restore should download and install each dependency parcel, without adding them to source control.
Troubleshooting
See Troubleshoot package restore.
Feedback
Submit and view feedback for
DOWNLOAD HERE
Posted by: valenzuelahostocall.blogspot.com
Post a Comment for "Use Nuget Package Restore To Download Them UPDATED"