Skip to content

Commit 9d1cf59

Browse files
authored
Document PC restore (NuGet#2216)
1 parent bde2e9d commit 9d1cf59

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

docs/consume-packages/Package-Restore.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ NuGet has two formats in which a project may use packages: [`PackageReference`](
142142

143143
## Restore using MSBuild
144144

145-
To restore packages listed in the project file with PackageReference, use the the [msbuild -t:restore](../reference/msbuild-targets.md#restore-target) command. This command is available only in NuGet 4.x+ and MSBuild 15.1+, which are included with Visual Studio 2017 and higher versions. Both `nuget restore` and `dotnet restore` use this command for applicable projects.
145+
Use the the [msbuild -t:restore](../reference/msbuild-targets.md#restore-target) command to restore packages listed in the project file (see [PackageReference](../../consume-packages/package-references-in-project-files.md)) and starting with MSBuild 16.5+, `packages.config` projects.
146+
147+
This command is available only in NuGet 4.x+ and MSBuild 15.1+, which are included with Visual Studio 2017 and higher versions.
148+
Starting with MSBuild 16.5+, this command can also restore `packages.config` based projects when run with `-p:RestorePackagesConfig=true`.
146149

147150
1. Open a Developer command prompt (In the **Search** box, type **Developer command prompt**).
148151

docs/reference/msbuild-targets.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ An example:
360360
1. Download packages
361361
1. Write assets file, targets, and props
362362

363-
The `restore` target works **only** for projects using the PackageReference format. It does **not** work for projects using the `packages.config` format; use [nuget restore](../reference/cli-reference/cli-ref-restore.md) instead.
363+
The `restore` target works for projects using the PackageReference format.
364+
`MSBuild 16.5+` also has [opt-in support](#restoring-packagereference-and-packages.config-with-msbuild) for the `packages.config` format.
364365

365366
### Restore properties
366367

@@ -386,7 +387,8 @@ Additional restore settings may come from MSBuild properties in the project file
386387
| RestorePackagesWithLockFile | Opts into the usage of a lock file. |
387388
| RestoreLockedMode | Run restore in locked mode. This means that restore will not reevaluate the dependencies. |
388389
| NuGetLockFilePath | A custom location for the lock file. The default location is next to the project and is named `packages.lock.json`. |
389-
| RestoreForceEvaluate | Forces restore to recompute the dependencies and update the lock file without any warning. |
390+
| RestoreForceEvaluate | Forces restore to recompute the dependencies and update the lock file without any warning. |
391+
| RestorePackagesConfig | An opt in switch, that restores projects with packages.config. Support with `MSBuild -t:restore` only. |
390392

391393
#### Examples
392394

@@ -431,6 +433,17 @@ msbuild -t:build -restore
431433

432434
The same logic applies to other targets similar to `build`.
433435

436+
### Restoring PackageReference and packages.config with MSBuild
437+
438+
With MSBuild 16.5+, packages.config are also supported for `msbuild -t:restore`.
439+
440+
```cli
441+
msbuild -t:restore -p:RestorePackagesConfig=true
442+
```
443+
444+
> [!NOTE]
445+
> `packages.config` restore is only available with `MSBuild 16.5+`, and not with `dotnet.exe`
446+
434447
### PackageTargetFallback
435448

436449
The `PackageTargetFallback` element allows you to specify a set of compatible targets to be used when restoring packages. It's designed to allow packages that use a dotnet [TxM](../reference/target-frameworks.md) to work with compatible packages that don't declare a dotnet TxM. That is, if your project uses the dotnet TxM, then all the packages it depends on must also have a dotnet TxM, unless you add the `<PackageTargetFallback>` to your project in order to allow non-dotnet platforms to be compatible with dotnet.

0 commit comments

Comments
 (0)