Anteckning
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Applies to: package consumption • Supported versions: 2.7+
Downloads and installs any packages missing from the packages folder. When used with NuGet 4.0+ and the PackageReference format, generates a <project>.nuget.props file, if needed, in the obj folder. (The file can be omitted from source control.)
On Mac OSX and Linux with the CLI on Mono, restoring packages is not supported with PackageReference.
Usage
nuget restore <projectPath> [options]
where <projectPath> specifies the location of a solution or a packages.config file. See Remarks below for behavioral details.
Options
- -ConfigFile- The NuGet configuration file to apply. If not specified, - %AppData%\NuGet\NuGet.Config(Windows), or- ~/.nuget/NuGet/NuGet.Configor- ~/.config/NuGet/NuGet.Config(Mac/Linux) is used.
- -DirectDownload- (4.0+) Downloads packages directly without populating caches with any binaries or metadata. 
- -DisableParallelProcessing- Disables restoring multiple packages in parallel. 
- -FallbackSource- (3.2+) A list of package sources to use as fallbacks in case the package isn't found in the primary or default source. Use a semicolon to separate list entries. 
- -Force- In PackageReference based projects, forces all dependencies to be resolved even if the last restore was successful. Specifying this flag is similar to deleting the - project.assets.jsonfile. This does not bypass the http-cache.
- -ForceEnglishOutput- (3.5+) Forces nuget.exe to run using an invariant, English-based culture. 
- -ForceEvaluate- Forces restore to reevaluate all dependencies even if a lock file already exists. 
- -?|-help- Displays help information for the command. 
- -LockFilePath- Output location where project lock file is written. By default, this is - PROJECT_ROOT\packages.lock.json.
- -LockedMode- Don't allow updating project lock file. 
- -MSBuildPath- (4.0+) Specifies the path of MSBuild to use with the command, taking precedence over - -MSBuildVersion.
- -MSBuildVersion- (3.2+) Specifies the version of MSBuild to be used with this command. Supported values are 4, 12, 14, 15.1, 15.3, 15.4, 15.5, 15.6, 15.7, 15.8, 15.9. By default the MSBuild in your path is picked, otherwise it defaults to the highest installed version of MSBuild. 
- -NoHttpCache- Prevents NuGet from using http cached packages. See Managing the global packages and cache folders. 
- -NonInteractive- Suppresses prompts for user input or confirmations. 
- -OutputDirectory- Specifies the folder in which packages are installed. If no folder is specified, the current folder is used. Required when restoring with a - packages.configfile unless- PackagesDirectoryor- SolutionDirectoryis used.
- -PackageSaveMode- Specifies the types of files to save after package installation: one of - nuspec,- nupkg, or- nuspec;nupkg.
- -PackagesDirectory- Same as - OutputDirectory. Required when restoring with a- packages.configfile unless- OutputDirectoryor- SolutionDirectoryis used.
- -Project2ProjectTimeOut- Timeout in seconds for resolving project-to-project references. 
- -Recursive- (4.0+) Restores all references projects for UWP and .NET Core projects. Does not apply to projects using - packages.config.
- -RequireConsent- Verifies that restoring packages is enabled before downloading and installing the packages. For details, see Package Restore. 
- -SolutionDirectory- Specifies the solution folder. Not valid when restoring packages for a solution. Required when restoring with a - packages.configfile unless- PackagesDirectoryor- OutputDirectoryis used.
- -Source- Specifies the list of package sources (as URLs) to use for the restore. If omitted, the command uses the sources provided in configuration files, see Configuring NuGet behavior. Use a semicolon to separate list entries. 
- -UseLockFile- Enables project lock file to be generated and used with restore. 
- -Verbosity [normal|quiet|detailed]- Specifies the amount of detail displayed in the output: - normal(the default),- quiet, or- detailed.
Also see Environment variables
Remarks
The restore command performs the following steps:
- Determine the operation mode of the restore command. - projectPath file type - Behavior - Solution (folder) - NuGet looks for a - .slnfile and uses that if found; otherwise gives an error.- (SolutionDir)\.nugetis used as the starting folder.- .slnfile- Restore packages identified by the solution; gives an error if - -SolutionDirectoryis used.- $(SolutionDir)\.nugetis used as the starting folder.- packages.configor project file- Restore packages listed in the file, resolving and installing dependencies. - Other file type - File is assumed to be a - .slnfile as above; if it's not a solution, NuGet gives an error.- (projectPath not specified) - NuGet looks for solution files in the current folder. If a single file is found, that one is used to restore packages; if multiple solutions are found, NuGet gives an error.
- If there are no solution files, NuGet looks for a packages.configand uses that to restore packages.
- If no solution or packages.configfile is found, NuGet gives an error.
 
- Determine the packages folder using the following priority order (NuGet gives an error if none of these folders are found): - The folder specified with -PackagesDirectory.
- The repositoryPathvalue inNuget.Config
- The folder specified with -SolutionDirectory
- $(SolutionDir)\packages
 
- The folder specified with 
- When restoring packages for a solution, NuGet does the following: - Loads the solution file.
- Restores solution level packages listed in $(SolutionDir)\.nuget\packages.configinto thepackagesfolder.
- Restore packages listed in $(ProjectDir)\packages.configinto thepackagesfolder. For each package specified, restore the package in parallel unless-DisableParallelProcessingis specified.
 
Examples
# Restore packages for a solution file
nuget restore a.sln
# Restore packages for a solution file, using MSBuild version 14.0 to load the solution and its project(s)
nuget restore a.sln -MSBuildVersion 14
# Restore packages for a project's packages.config file, with the packages folder at the parent
nuget restore proj1\packages.config -PackagesDirectory ..\packages
# Restore packages for the solution in the current folder, specifying package sources
nuget restore -source "https://api.nuget.org/v3/index.json;https://www.myget.org/F/nuget"