CMake属性VS_USER_PROPS被静默忽略:Visual Studio 2019项目无法导入GStreamer相关Props文件
Let's break down why your videolib.deps.props isn't being picked up, and walk through actionable fixes:
1. The Primary Issue: Incorrect Path to Your Props File
The VS_USER_PROPS property expects a path relative to the generated project file's directory (where your .vcxproj lives in the build folder) or an absolute path. When you set it to just "videolib.deps.props", CMake looks for the file in build/videolib—but your props file is almost certainly in your source directory (either the root or videolib subfolder), so it can't find it and silently ignores the property.
Fix the Path
Update your videolib/CMakeLists.txt to use an absolute path pointing directly to your props file:
# If your props file is in the videolib subdirectory: set_target_properties(videolib PROPERTIES VS_USER_PROPS "${CMAKE_CURRENT_SOURCE_DIR}/videolib.deps.props") # If it's in the root project directory instead: # set_target_properties(videolib PROPERTIES VS_USER_PROPS "${PROJECT_SOURCE_DIR}/videolib.deps.props")
CMAKE_CURRENT_SOURCE_DIR gives the full path to the folder containing the current CMakeLists.txt, ensuring CMake writes the correct location into the generated .vcxproj.
2. Verify the Fix
After re-running CMake configuration (cmake -S .. -G "Visual Studio 16 2019"), open the generated videolib.vcxproj in a text editor. You should see a line like this near the top:
<UserProps>D:/projects/videolib/videolib/videolib.deps.props</UserProps>
If this line exists, Visual Studio will load the props file when opening the project.
3. Optional: Make Your Props File More Flexible
Your current props uses hardcoded GStreamer paths. Swap them for the official GStreamer environment variable (set automatically during MSVC installation) to avoid breakage if your GStreamer location changes:
Update videolib.deps.props:
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ImportGroup Label="PropertySheets"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Label="LocalAppDataPlatform" /> <Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\glib-2.0.props" /> <Import Project="$(GSTREAMER_1_0_ROOT_MSVC_X86_64)\share\vs\2010\libs\gstreamer-1.0.props" /> </ImportGroup> </Project>
4. Alternative: Use GStreamer's CMake Module (Cross-Platform Friendly)
If you want to ditch Visual Studio props entirely for a more portable build, use GStreamer's official CMake configuration:
- Add this to your root CMakeLists.txt:
# Point CMake to GStreamer's CMake config directory set(GSTREAMER_DIR "C:/gstreamer/1.0/msvc_x86_64/lib/cmake/GStreamer-1.0") find_package(GStreamer REQUIRED COMPONENTS core app)
- Update your
videolib/CMakeLists.txtto link against GStreamer's targets:
add_library(videolib SHARED) target_link_libraries(videolib PRIVATE videolib-common GStreamer::gstreamer GStreamer::gstapp)
CMake will automatically handle include directories, linker flags, and dependencies—no props files required.
内容的提问来源于stack exchange,提问作者Arks

