Search code examples
c++visual-studiovisual-c++include-path

Include path relative to props file in visual studio


I'm trying to create property file with include path to use in all my c++ project.

Here is repository structure.

/
    /Libs
        /Libs2
            A.h
         B.h
    /Sln1
        Sln1.sln
        Proj1.vcxproj
    Sln2.sln
    Proj2.vcxproj
    Props.props

I want use property file (Props.props) to add the following include path to both projects ( C:\\Libs;C:\\Libs\Libs2).

Currently I have macro in my property file:

Name          Value
ProjRoot      C:\<path to rep root>

And I use it in include string: $(ProjRoot)\Libs;$(ProjRoot)\Libs\Libs2

The problem with this solution is hardcoded absolute path in macro value. If my repository will be cloned on another drive I will have to change it manually.

Can I use path relative to property file in macro value?

I.e.:

Name          Value
ProjRoot      ./

Where ./ will resolve to path of Props.props file in all projects which will use this property file.

I cannot use $(SolutionDir) and $(ProjectDir) because there are may solutions and projects in different nesting level so path relative to them would not work.

Thank you.


Solution

  • Do do this one should manually edit props file and include the following:

    <PropSheetPath>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))</PropSheetPath>
    

    This will create property PropSheetPath with property file folder.

    Found the answer here:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/2817cae7-3a71-4701-839a-9bf47af7c498/property-sheets-macro-to-reference-location-of-property-sheet?forum=vcgeneral