question

DavidThielen-3337 avatar image
0 Votes"
DavidThielen-3337 asked MarcelloStagni-7580 published

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).


vs-msbuilddotnet-package-management
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DylanZhu-MSFT avatar image
3 Votes"
DylanZhu-MSFT answered DanielArroyo-5860 commented

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 directory

The 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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Dylan;

I tried that - it didn't work. MSBuild returned immediately after doing nothing.

I did find a solution. I run "nuget.exe restore [sln_file]"

0 Votes 0 ·

This works for me, i was using the commands in the documentation, but i was using them separately (-t:restore) (-p:RestorePackagesConfig=true)

In Jenkins i have to use 2 commands

msbuild [sln file filter] -t:restore -p:RestorePackagesConfig=true
msbuild [sln file filter]

First one only download the packages, the last one builds the solution

0 Votes 0 ·
MarcelloStagni-7580 avatar image
0 Votes"
MarcelloStagni-7580 answered MarcelloStagni-7580 published

If you need to restore and build at once, you can do

msbuild [sln file filter] -t:restore,build -p:RestorePackagesConfig=true

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.