CMake and MsVS-NuGet

2019-02-11 12:40发布

问题:

I'm currently developing a desktop application, using the C++ REST SDK (codename Casablanca), Qt5 and some other libraries.

For the project setup, I use CMake.

How to get CMake to install NuGet Packages?

I now have to install it each time manually, if I rerun CMake, which isn't really an option.

回答1:

The command line reference of NuGet is located at http://docs.nuget.org/docs/reference/command-line-reference

You can install packages using the nuget install or nuget restore command. nuget update updates the installed packages (restore must be run beforhand).

You can instruct cmake to run NuGet before every build by using:

add_custom_command(TARGET ${PROJECT_NAME}
    PRE_BUILD
    COMMAND nuget restore ${CMAKE_BINARY_DIR}\yourSolution.sln
)

or at configure time using execute_process.

You can prepare the nuget config file using configure_file or use appropriate nuget install commands directly.