vcpkg is Now Included with Visual Studio
As of Visual Studio 2022 version 17.6, the vcpkg C/C++ package manager is included as an installable component for the C++ Desktop and C++ Gaming workloads. You can also find it in the installer by searching for vcpkg package manager under the Individual components tab. Using the Visual Studio Copy of vcpkg After you install or update Visual Studio with the vcpkg component checked, the package manager will be installed in your Visual Studio installation directory. You can run vcpkg commands directly from the Developer Command Prompt for Visual Studio or Developer PowerShell for Visual Studio. This also works for the equivalent consoles embedded in the IDE. vcpkg output is localized according to your Visual Studio language. Both ports and artifacts are supported. As with all copies of vcpkg, to initialize it with the IDE, you will first need to run vcpkg integrate install before running other commands. This will enable MSBuild and CMake IDE integration with this copy of vcpkg. You will need to run this command with administrator privileges. Importantly, the copy of vcpkg that ships with the IDE supports manifests but does not support classic mode. The reason for this is that classic mode requires write access to the vcpkg installation directory, but in this case it is in Program Files and the Visual Studio installer requires ownership of it. You can still use classic mode by running integrate install to an external copy of vcpkg instead. Recap: Existing vcpkg IDE Integration vcpkg was already supported by Visual Studio even before this update. Below is a recap of what you can do with the package manager in the IDE. In order to enable this functionality, you must have run vcpkg integrate install once in the past. Once that is done, you do not need to re-run this command. IntelliSense Support Code calling an external library installed with vcpkg will have working IntelliSense, including autocompletion, semantic colorization, code navigation, and refactoring features. MSBuild Integration There are several MSBuild properties for configuring vcpkg for your project. These are available under Configuration Properties > vcpkg. Importantly, you will want to set “Use Vcpkg Manifest” to “Yes” if you intend to use vcpkg in manifest mode with your MSBuild project. Once this is turned on, if you have a vcpkg.json file in your project, vcpkg will automatically be called every time you do a build to check if any dependencies need to be installed or updated. The package manager will then restore missing dependencies, allowing the build to proceed. CMake Integration The IDE automatically picks up the vcpkg.cmake toolchain file and passes it to the CMake command line behind the scenes, allowing you to use the CMake IDE experience seamlessly. Furthermore, if you have a vcpkg.json manifest file in your project, vcpkg will automatically run when CMake configures itself on project load or when the CMake cache is manually generated. The package manager will automatically install or update any missing dependencies, in accordance with the manifest file, allowing you to build your project successfully. Furthermore, CMake find_package() calls also have IntelliSense autocompletion for various libraries available via vcpkg. Environment Activation with vcpkg Artifacts If you have the Desktop development with C++ or Linux and embedded development workload installed in Visual Studio, you can automatically install and activate tools required for your […]
