Issue
I am writing a Windows Desktop App in C++. There is an external library that has code that is only available on GitHub. I am now looking for a way to automatically download the library when my Visual Studio project builds so that I do not have to manually download the library on every PC that I debug my application on (at least 3, since it is a shared project).
In CMake I have stumbled upon ExternalProject_Add(), is there anything similar to this for a Visual Studio project? My solution now is to integrate the library as a git submodule, but it feels like there has to be a better way. I am using Visual Studio 2022.
Solution
Visual Studio integrates Nuget and VCPKG for library management.
In addition, you can also use your own scripts in Visual Studio: Project properties -> Build Events -> Pre-Build Events. Create a powershell file in project and execute it before building the project.
Eg.
Pre-Build Events Command Line: powershell -ExecutionPolicy Bypass -File "test.ps1"
check if there is an opencv folder in the current folder, if not, download it from GitHub.
test.ps1:
$folderExists = (Get-ChildItem | Where-Object { $_ -like "*opencv*" }).Count -gt 0
if ($folderExists) {
Write-Host "opencv exists"
} else {
Write-Host "opencv do not exist"
git clone https://github.com/opencv/opencv.git
}
Answered By - Minxin Yu - MSFT Answer Checked By - Mildred Charles (WPSolving Admin)