1

I'm currently looking for a way to trigger a NuGet update on build in Visual Studio 2017.

I'm using VS2017 Pro. My codebase consists of multiple solutions which break the code into layers (data access / business logic / ui / application / etc). When a solution builds, it generates one or more NuGet packages which are then consumed by projects further up the 'food chain'. Automating the NuGet update on our build server is trivial, however it would be nice if we could configure our development environments such that it always attempts to get the latest NuGet packages on build akin to how Package Restore works.

I've come across a lot of information regarding older versions of Visual Studio/NuGet that include updating the auto-generated nuget.targets files, however these aren't created in VS2017 with NuGet package manager 4.6.x (unless I'm doing something wrong!)

Any help or advice would be greatly appreciated.

Danielle Summers
  • 366
  • 2
  • 11

1 Answers1

0

NuGet Update on build (VS2017 Pro)

If pre-build events are too late for you, you can try to add a new project to the solution with pre-build event/post-build event to update the nuget packages, which uesd by other projects/solutions:

<YourNuGetPath>\nuget.exe update "<YourSolutionPath>\xxxx.sln"

Or

<YourNuGetPath>\nuget.exe update "<ThePackages.configFilePath>\Packages.config"

In this case, you can build this new add project to get latest NuGet packages for these projects/solution using nuget packages.

Besides, if you do not want to build this project before those consuming nuget package projects, you can let those projects reference this new add project, Visual Studio will build it before building those consuming nuget package projects.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • I'll give this a try and see how it goes. Thanks for your feedback :) – Danielle Summers Jun 08 '18 at 07:19
  • @Danielle Summers, What about this issue in your side? Would you please share the latest information? – Jack Zhai Jun 12 '18 at 01:25
  • Sorry, work had me dragged onto a different project. Once I get chance I'll give this a try and mark this as an answer if it proves suitable. – Danielle Summers Jun 12 '18 at 07:19
  • Sorry again about the long delay. Sadly this doesn't work as I'd hoped. Creating an empty project with only a pre-build event to update the solution. If build on it's own, it does update the solution, but when configured to build first (through project dependencies), it takes time to complete and the build doesn't wait for it - so one or more projects get built before the update has finished indexing the package source. :( – Danielle Summers Jun 13 '18 at 14:00