Visual studio macro with a props file.

Short question:

I want to be able to use the path of the props file as a macro from inside the props (for example, the ability to refer to the project directory as $(ProjectDir) )

Long task

I use the details to add links to various third-party libraries.

It is simple if I can specify the absolute path to a third-party library.

However, I want to indicate a relative path - as different team members use a different location for the version control tree. is there any way to add such relative paths to the props file?

specifying the path relative to the project directory is also not a good solution, since the location of the projects is not fixed (therefore, for one project I will need $(SolutionDir)\..\XXXX , and for another I will need $(SolutionDir)\..\..\XXXX

+6
source share
3 answers

I would suggest that you have conflicting interests:

  • Provide the props file that is used by all developers and eliminate the need for developers to qualify #include paths
  • Allow all developers to determine the root location of these #include paths.

This is not the answer you were looking for, but I suggest you use a different approach.

Two come to mind:

  • Let each developer define assembly time macros in the Microsoft.Cpp.x64.user file, for example $(MY_PROJECT_ROOT) , and specify directories in relation to these macros in the verification details file.

  • Use an absolute path in the details file with verification, but make this absolute path a connection point, for example X:\ . Each developer will determine where X:\ points to.

Number 2 has the advantage that it is easier for him to switch between connecting lines. Perhaps, say, release 1.0 of your application Beta 2.0 of your application. You can use the same props file in both cases; the developer simply runs a batch file to switch transitions when switching from one trunk to another.

However, number 1 has the advantage that this solution is fully included in the IDE.

+1
source

Solution: $(MSBuildThisFileFullPath) (or rather $(MSBuildThisFileDirectory) ) . (which is noted in passing here .)

If it is used in a properties file ( .props ), it will refer to this / dir file of the property itself. (Note: When used at the .vcxproj level .vcxproj it will reference the project file / dir.

Tested with VS2013 RC and VS2010.

+16
source

@John Dibling: This is a bad solution for any group that runs on parallel branches; you will have to constantly change your environment or locally edit .props files in each branch. It's a pity when you constantly switch branches.

Unfortunately, I cannot find a better solution. In my head, there would be something where the top level .props defines a custom macro, such as PROJECT_ROOT (defined as "../../"), and then other .props files inherit and use this macro. This way you can share one .props file with solutions with several different relative paths. Unfortunately, it seems that user macros are not inherited in .props files.

There must be a real solution that does not include local configuration of the build environment, given the static directory structure across multiple branches.

EDIT:

Looks like I found a solution for this, for real. Basically you have one relativepath.props file that defines a custom macro with your relative path, another props file that uses this macro for all its paths, and then the file that you actually import into your vcxproj will look like this, including both sheets of properties. This is the only way to get it to use a macro from one file in other files.

Then different solutions in different relative paths can use different paths, and properties are defined only once in realprops.props.

  <ImportGroup Label="PropertySheets"> <Import Project="relativepath.props" /> <Import Project="realprops.props" /> </ImportGroup> 
+5
source

Source: https://habr.com/ru/post/914646/


All Articles