Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild 15 NuGet restore and build

I'm trying to get the new MSBuild NuGet restore feature to work and having an odd problem.

If I do:

msbuild.exe mySolution.sln /p:Configuration=Release 

I get an error about missing packages. This is expected behaviour. However, if I do:

msbuild.exe mySolution.sln /p:Configuration=Release /t:restore 

MSBuild "succeeds" but just creates an obj folder with some files relating to the NuGet restore i.e. no bin\Release\ folder.

In order to restore and build I have to issue both commands above (restore first, obviously).

I have upgrade all of the packages.config files to use the latest PackageReference in the .csproj file.

Is there a way to both restore and build using a single command?

like image 710
Tom Avatar asked Oct 16 '17 15:10

Tom


People also ask

Does MSBuild restore NuGet packages?

Restore using MSBuild This command is available only in NuGet 4. x+ and MSBuild 15.1+, which are included with Visual Studio 2017 and higher versions. Starting with MSBuild 16.5+, this command can also restore packages. config based projects when run with -p:RestorePackagesConfig=true .

How do I reinstall a NuGet package?

Switch to the Browse tab, search for the package name, select it, then select Install). For all packages, delete the package folder, then run nuget install . For a single package, delete the package folder and use nuget install <id> to reinstall the same one.

How do you clean MSBuild solution?

Cleaning up specific projects: msbuild MyProjectFile1 /t:Clean msbuild MyProjectFile2 /t:Clean ... This has to be repeated for all projects you need to clean, because MSBuild only accepts single project on command line.


1 Answers

MSBuild 15.5 will introduce a /restore flag that implements this functionality.

Before that, it is theoretically possible to run both a restore and build in the same invocation (/t:Restore;Build) but it is unsafe as MSBuild may cache project files and not see changes made by a NuGet restore. The /restore option will clear all the affected caches before resuming with the normal build.

like image 85
Martin Ullrich Avatar answered Sep 21 '22 20:09

Martin Ullrich