none
How does a condition exists evaluate for a pre-processor definition in vcxproj file. RRS feed

  • Question

  • I am trying to run MSBuild with following command 

    msbuild socwatch.sln /t:rebuild /p:Configuration=Release /p:platform=x64

    and another build using the command

    msbuild socwatch.sln /t:rebuild /p:Configuration=Release /p:platform=x64 /p:SOC='IAP'

    My .vcxproj file has this setting

    <PreprocessorDefinitions Condition= "!exists('$(SOC)')">%(PreprocessorDefinitions);IAP</PreprocessorDefinitions>
    <PreprocessorDefinitions Condition="'$(SOC)'=='IAP'">%(PreprocessorDefinitions);IAP</PreprocessorDefinitions>

    The purpose of the first PreprocesseorDefinition is to declare a pre-processor directive called IAP if SOC is not mentioned as a command line parameter for MSBuild. But the first line never works. How to implement this ? 


    • Edited by Prasad Nair Saturday, September 28, 2019 3:07 AM
    Friday, September 27, 2019 1:17 AM

All replies

  • Hi Prasad,

    Welcome to the MSDN forum.

    "The first line never works" means that the first msbuild command line has the error which cannot  assign your value to this parameter "PreprocessorDefinitions". The problem is that you cannot add a condition to metadata in an item created in an itemgroup. It is unrecognizable.

    For example, the ClCompile is a item in Itemgroup and PreprocessorDefinitions is a metadata which cannot add a judgement statement like Condition. If you add a judgement statement, the assignment will fail. This is msbuild's established internal identification method.

    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
        <ClCompile>   
          <PreprocessorDefinitions Condition= "!exists('$(SOC)')">%(PreprocessorDefinitions);IAP
       </ClCompile>
    </ItemDefinitionGroup>

    So we commend that you can add the judgement statement in the item. It will assign a perfect value based on the conditions you give, but be careful to add conditions to the platform you need to compile.

    Like:

    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64' and (!exists('$(SOC)') or '$(SOC)'=='IAP')">
        <ClCompile>    
          <PreprocessorDefinitions>%(PreprocessorDefinitions);IAP
          </PreprocessorDefinitions>    
        </ClCompile>
      </ItemDefinitionGroup>

    Any feedback will be expected.

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com




    Friday, September 27, 2019 11:32 AM
  • Hi Parsad,

    Did you try my suggestions to handle your issue? Perhaps you should add the Condition statement in the related Item.

    If my reply is helpful for you to solve your issue, please remember to mark it as answer. If your issue still persists, please feel free to let us know.

    Thanks for your understanding.

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, September 30, 2019 9:29 AM