Describe the bug
I would like to use vcpkg in a CMake project that also includes .NET targets (e.g. relevant when having one project that has both C++, C++/CLI and .NET components, all built with CMake).
When providing /path/to/vcpkg/scripts/buildsystems/vcpkg.cmake as CMAKE_TOOLCHAIN_FILE cache variable, I get the following error for every .NET target in the project:
CMake Error in CMakeLists.txt:
The target "TARGET_NAME" does not currently support add_custom_command as
the Visual Studio generators have not yet learned how to generate custom
commands in .Net SDK-style projects.
This is unfortunate, as it prevents me using vcpkg in such project (or forces me to split up the project in some way).
Environment
OS: Windows
Compiler: MSVC 17.9 (Visual Studio 2022)
To Reproduce
For easy reproduction, do the following:
Create a project with an empty vcpkg.json file and an empty Program.cs file at the root directory. In the CMakeLists.txt add the following lines:
Run the following command: cmake -S /path/to/repo -B /path/to/build/dir -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE="/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake"
This will yield the error message shown above (with "HelloWorld" as TARGET_NAME).
Expected behavior
I would expect the inclusion of the vcpkg toolchain file to not influence .NET targets.
Failure logs
See attached file for logs obtained by running the CMake command shown above with --trace.
cmake-trace.txt
Skimming through the logs makes me assume that /path/to/vcpkg/scripts/buildsystems/vcpkg.cmake(612) might be the problematic add_custom_command call (however, I don't 100% understand what is happening in here).
Ideally, we should not do the add_custom_command for .NET targets to resolve this issue.
Describe the bug I would like to use vcpkg in a CMake project that also includes .NET targets (e.g. relevant when having one project that has both C++, C++/CLI and .NET components, all built with CMake). When providing
/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake
asCMAKE_TOOLCHAIN_FILE
cache variable, I get the following error for every .NET target in the project:This is unfortunate, as it prevents me using vcpkg in such project (or forces me to split up the project in some way).
Environment
To Reproduce For easy reproduction, do the following:
vcpkg.json
file and an emptyProgram.cs
file at the root directory. In theCMakeLists.txt
add the following lines:cmake -S /path/to/repo -B /path/to/build/dir -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE="/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake"
This will yield the error message shown above (with "HelloWorld" as
TARGET_NAME
).Expected behavior I would expect the inclusion of the vcpkg toolchain file to not influence .NET targets.
Failure logs See attached file for logs obtained by running the CMake command shown above with
--trace
. cmake-trace.txtSkimming through the logs makes me assume that
/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake(612)
might be the problematicadd_custom_command
call (however, I don't 100% understand what is happening in here). Ideally, we should not do theadd_custom_command
for .NET targets to resolve this issue.