May 18th, 2023

vcpkg is Now Included with Visual Studio

Augustin Popa
Senior Product Manager

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.

Image VS Installer with vcpkg checkbox

 

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.

Image vcpkg MSBuild properties

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 development environment if they are configured as vcpkg artifacts and they are defined in a manifest file. For more details, see vcpkg Environment Activation in Visual Studio.

 

Known Issues

The following features do not work yet with the built-in copy of vcpkg but are planned to be fixed in future updates to Visual Studio:

  • The Tools > Options > vcpkg package manager setting that lets you point to a custom copy of vcpkg for managing vcpkg artifacts still exists and works for its intended purpose but does not replace the built-in copy of vcpkg in other contexts like running commands in the terminal. In the future, we plan to use this setting as a way for users to globally set their preferred copy of vcpkg within VS rather than having to run vcpkg integrate install from that copy of vcpkg.
  • Being able to use the built-in copy without having to run vcpkg integrate install
  • The quick action lightbulb that appears when an IntelliSense error detects a code reference to a library that cannot be found and offers to install it with vcpkg will not work with the built-in copy as this feature uses classic mode.

 

Give Us Feedback

Try out the latest version of Visual Studio 2022 and give us feedback! To learn more about vcpkg, visit the website.

If you have feedback about Visual Studio features and how vcpkg integrates with Visual Studio, please visit the Help > Send Feedback menu in Visual Studio or visit the Visual Studio Developer Community feedback website.

If you have feedback about the vcpkg package manager itself, please file issues or start discussion threads in the vcpkg GitHub repository.

 

Category
C++Vcpkg
Topics
vcpkg

Author

Augustin Popa
Senior Product Manager

Product manager on the Microsoft C++ team, currently working on vcpkg.

7 comments

Discussion is closed. Login to edit/delete existing comments.

  • Jaiganésh Kumaran

    It would be really nice to have the Package Manager tab (currently used for NuGet) to search, install and update vcpkg packages. I personally much prefer using a GUI rather than editing a JSON file (manifest mode) or typing a command.

  • Andrew Robbins

    Is there any mechanism for updating the portfiles? It doesn’t seem that git pull is an option (nor would I expect it to be, as vcpkg is managed by vs). Primary issue is that MSYS2 has a habit of removing older releases from the mirrors which makes any old portfiles unusable. As of today, for instance, anything that tries to download msys2-runtime fails with a 404.

    • Nathan Cheadle

      This is the number one thing to resolve before this feature is legitimately useful. So many times on the github issues page if someone has a port file issue the first response is pull latest and try again.

      msys2 is a very very common culprit, but not the only one.

      Asset caching is another possible option but it shouldn't be a requirement to set up asset caching just to use vcpkg as included with VS. Ideally...

      Read more
  • Michael Taylor

    >> 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.

    I think it is important to point out here that you have to run this command as an administrator. When you run the command it tries to insert a .props file into the shared MSBuild path for CPP and that will fail without admin privileges: `error: failed to install system...

    Read more
    • Augustin PopaMicrosoft employee Author

      Thanks for pointing this out. I have edited the post to clarify this.

      • David Lowndes

        Hmm, strangely, installing VS2022 latest preview on a clean Win10 system, and from an Admin “x64 Native Tools Command Prompt for VS2022 Preview”, I still get that error!

        C:\Windows\System32>vcpkg integrate install
        error: failed to install system targets file to C:\Program Files (x86)\MSBuild/Microsoft.Cpp/v4.0/V140/ImportBefore/Default/vcpkg.system.props

      • David Lowndes

        And even more strangely…
        Repeating the command in the same (Admin) command window, appears to succeed:

        C:\Windows\System32>vcpkg integrate install
        Applied user-wide integration for this vcpkg root.
        CMake projects should use: “-DCMAKE_TOOLCHAIN_FILE=C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/vcpkg/scripts/buildsystems/vcpkg.cmake”

        All MSBuild C++ projects can now #include any installed libraries. Linking will be handled automatically. Installing new libraries will make them instantly available.