MSBuild 15 NuGet restore and build

2019-06-15 19:04发布

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?

1条回答
祖国的老花朵
2楼-- · 2019-06-15 19:34

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.

查看更多
登录 后发表回答