Sometimes, when I want to move the project from path A:/B/C to path A:B/C/D/E, the
relative path of the project have to be changed. I think I could write a small program to
deduce the relative path after changed, it would be better if I could change the
"Additional manipulate Directories" by C++ but not by my own hand.
My idea is

//absolute path before moving"
//a lot of relative "Additional Directories"

//absolute path after moving
//the program will dumb the new "relative path" at here

I could just copy the new relative path and copy them to the ""Additional manipulate Directories"
But how could I make the "Additional manipulate Directories" change automatically?
Thanks a lot

Dani AI

Generated

Short summary and options (for and future readers): moving a Visual C++ project will break any hard-coded or absolute paths in project settings such as the C/C++ "Additional Include Directories". Two practical, robust choices are (A) make the project resilient so paths do not need editing (use macros and shared property sheets), or (B) update the project/property-sheet files automatically with a small tool that edits the MSBuild XML (.vcxproj / .props). 's CMake suggestion is a good cross-platform alternative, but native VS options are shown below.

Use shared property sheets and macros first. Create a reusable .props and put common include/library paths there; assign it with the Property Manager so multiple projects inherit the same values. In a sheet, append values rather than overwrite them by using the MSBuild append pattern (for example: <AdditionalIncludeDirectories>$(MY_LIB)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>), which preserves other entries. This is the least brittle approach: store the .props in the repo (relative to the solution) so moves rarely require edits. See MS docs on property sheets and the recommended workflow. Share or reuse Visual Studio project settings. (learn.microsoft.com)

If a program must rewrite paths, edit the project/property-sheet XML safely (do not string-replace). .vcxproj and .props are MSBuild XML; the compiler option maps to <ClCompile><AdditionalIncludeDirectories>...</AdditionalIncludeDirectories></ClCompile>. Implement these steps in a small tool:

  • backup the file, parse as XML (MSXML, tinyxml2, pugixml).
  • compute the new relative path (std::filesystem::relative in C++17 is handy).
  • update every applicable ItemDefinitionGroup/ClCompile node for all configurations and include %(AdditionalIncludeDirectories) when inserting values.
  • save and (if open in VS) reload the project. The MSBuild/VC project layout and the CL mapping are documented. MSBuild CL mapping / .vcxproj guide. (devblogs.microsoft.com)

Alternative: automate from inside Visual Studio using the Visual C++ automation model (VCProject/VCPropertySheet) or EnvDTE if the tool will run while the IDE is loaded; this is the right choice for IDE-integrated tooling. Also consider Directory.Build.props or repo-level .props for solution-wide defaults, but note MSBuild reads imported files during evaluation so edits may not take effect until a reload/rebuild. Visual C++ project model / automation · Customize-by-directory / Directory.Build.props. (pvs-studio.com)

Practical cautions: always back up project files before programmatic edits; test on one configuration first; prefer macros or a shared .props to repeated edits.

Recommended Answers

All 2 Replies

What you are describing is a build script, that is what you need. Personally, I am not familiar with Visual C++'s build system and the possibilities it offers to write build scripts. The main reason I'm not familiar with it is because it generally sucks and most large cross-platform projects use another build system which is independent of a particular IDE, compiler or OS.

I highly recommend that you take a look at Cmake. This build system will allow you to create very fancy build scripts (like automatically updating time-stamps on files, generating and applyling version numbers, creating custom build-targets such as doxygen documentation, etc. etc.). And, btw, your problem of updating the directory is basically a non-issue when using Cmake, it will take care of all that, including scanning the computer to find include directories and import libraries for external packages and stuff like that.

Thanks a lot, I will give it a try

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.