You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/consume-packages/Package-Restore.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,7 +142,10 @@ NuGet has two formats in which a project may use packages: [`PackageReference`](
142
142
143
143
## Restore using MSBuild
144
144
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`.
146
149
147
150
1. Open a Developer command prompt (In the **Search** box, type **Developer command prompt**).
Copy file name to clipboardExpand all lines: docs/reference/msbuild-targets.md
+15-2Lines changed: 15 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -360,7 +360,8 @@ An example:
360
360
1. Download packages
361
361
1. Write assets file, targets, and props
362
362
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.
364
365
365
366
### Restore properties
366
367
@@ -386,7 +387,8 @@ Additional restore settings may come from MSBuild properties in the project file
386
387
| RestorePackagesWithLockFile | Opts into the usage of a lock file. |
387
388
| RestoreLockedMode | Run restore in locked mode. This means that restore will not reevaluate the dependencies. |
388
389
| 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. |
390
392
391
393
#### Examples
392
394
@@ -431,6 +433,17 @@ msbuild -t:build -restore
431
433
432
434
The same logic applies to other targets similar to `build`.
433
435
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
+
434
447
### PackageTargetFallback
435
448
436
449
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