Search code examples
c++visual-studiovisual-c++projects-and-solutions

User macro having different values depending on configuration


In Visual C++ 2012, I want to have a user-defined macro (the ones used in project property sheets) whose value can be defined differently for each configuration.

I have created user macros with help of this article, but changing its value for a specific configuration changes it for all configurations.

Is there a way to have its value defined differently at each configuration?


Solution

  • Found answer in this post: Using Visual Studio project properties effectively for multiple projects and configurations

    In the newly created .props file, replace the first PropertyGroup with the following

      <PropertyGroup Label="UserMacros">
        <MilVersion Condition="'$(Configuration)'=='Debug-ConfigA'">Value1</MilVersion>
        <MilVersion Condition="'$(Configuration)'=='Debug-ConfigB'">Value2</MilVersion>
        <MilVersion Condition="'$(Configuration)'=='Release-ConfigA'">Value1</MilVersion>
        <MilVersion Condition="'$(Configuration)'=='Release-ConfigB'">Value2</MilVersion>
      </PropertyGroup>
    

    In this code, the user macro $(MilVersion) will be Value1 in configurations (Debug|Release)-ConfigA, and Value2 in configurations (Debug|Release)-ConfigB.