It's 2023 and it still doesn't work. Also is this supposed to be -t:restore or /restore? What is the proper way to perform a restore from MSBuild? Anybody know?
How can I get MSBuild to restore any needed NuGet packages
I've looked at a ton of articles on this including here and here. None provide a solution that I can get to work.
I have everything turned on for automatically doing this in VisualStudio. But on our build machine we build the .sln files using MSBuild, not by opening up VisualStudio. So in MSBuild how can I best do this?
All of our .sln files are for VisualStudio 2019 and set to defaults on handling NuGet (I believe).
3 answers
Sort by: Newest
-
-
Marcello Stagni 11 Reputation points
2022-04-08T14:53:28.87+00:00 If you need to restore and build at once, you can do
msbuild [sln file filter] -t:restore,build -p:RestorePackagesConfig=true
-
Dylan Zhu-MSFT 6,406 Reputation points
2020-12-30T06:42:55.877+00:00 Hi DavidThielen,
You could run this command:
msbuild [sln file] -t:restore -p:RestorePackagesConfig=true
, which could work on my side.
Note: the package.config file locates at the project directoryThe document: Restoring PackageReference and packages.config with MSBuild
Best Regards,
Dylan
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our **documentation to enable e-mail notifications if you want to receive the related email notification for this thread.**