Reputation: 2268
Is it possible to restore packages during the build using MSBuild only if projects are still using packages.config?
Upvotes: 17
Views: 17203
Reputation: 15207
EDIT: This answer was outdated by recent MSBuild enhancements. See @irvnriir answer.
According to documentation[1]:
The
restore
target works only for projects using the PackageReference format. It does not work for projects using thepackages.config
format; use nuget restore instead.
So you will have to use nuget.exe
restore instead. Look my other answer for that.
[1] https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets
Upvotes: 5
Reputation: 796
https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-target
MSBuild 16.5+ also has opt-in support for the packages.config format.
Use:
msbuild -p:RestorePackagesConfig=true -t:restore
msbuild -t:build
Upvotes: 31
Reputation: 359
As far as I can read on https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore it is possible:
MSBuild: use the msbuild /t:restore command, which restores packages packages listed in the project file (PackageReference only). Available only in NuGet 4.x+ and MSBuild 15.1+, which are included with Visual Studio 2017.
nuget restore
anddotnet restore
both use this command for applicable projects.
Upvotes: 0