how to change CLCompile property for all projects【转】http://social.msdn.microsoft.com/Forums/en-US/ms...

讨论了如何在不修改vcxproj文件的情况下,通过导入自定义属性文件来覆盖项目的特定编译链接选项。提供了实现方法及注意事项。

how to change CLCompile property for all projects... 

  • Thursday, January 12, 2012 7:30 PM
     
    65 Points
     
     
     
    Sign In to Vote
    0

    We have a requirement i.e. we do not want to modify vcxproj files but have an import of .prop file in .vcxproj. This prop file will be imported only if the file exists. The import will be at the bottom of the .vcxproj so that it is the last file that is being imported. In the custom prop file we want to override CLCompile\Link options i.e. override the values that exist in .vcxproj file

    We tried the following but it does not work i.e. vcxproj file has DebugInformationFormat set to "EditAndContinue" while custom.user.props file has "ProgramDatabase" value for DebugInformationFormat. The  DebugInformationFormat value does not get set to "ProgramDatabase". How do we achieve the above requirement.

    Each and every .vcxproj file will have the following import statement

        <Import Project="$(DIRNAME)\Custom.user.props" Condition="exists('$(DIRNAME)\Custom.user.props')"  />

     

    $(DIRNAME)\Custom.user.props will have the following:

    <?xml version="1.0" encoding="utf-8"?>

    <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

      <ItemDefinitionGroup>

        <ClCompile>

          <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>

        </ClCompile>

      </ItemDefinitionGroup>

    </Project>

     







    • Edited by ChandraP Thursday, January 12, 2012 10:04 PM
    •  
     

All Replies

  • Friday, January 13, 2012 6:32 AM
    UIS
     
    9,705 Points
    Moderator
     
      Answered  Has Code
    Sign In to Vote
    0

    Hi ChandraP,

    I think your idea should work, and I tested it on my side. The prop file is as following:

     

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ImportGroup Label="PropertySheets" />
      <PropertyGroup Label="UserMacros" />
      <PropertyGroup />
      
      <ItemDefinitionGroup>
        <ClCompile>
          <DebugInformationFormat>OldStyle</DebugInformationFormat>
        </ClCompile>
      </ItemDefinitionGroup>
      <ItemGroup />
    </Project>
    

    And the last few lines of VCXProj is as following:

     

     

     <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
      
      
      <ImportGroup>
        <Import Project ="test1.props" Condition= "exists('test1.prop')"/>
      </ImportGroup>
      
      <Target Name="msg">
        <Message Text=" %(ClCompile.DebugInformationFormat)" />
      </Target>
    
    </Project>
    

    I defined a target called msg to show the value of debuginformationformat, as the result, if the prop file exists, it is OldStyle, otherwise it is EditandContinue.

     

    If I misunderstand you, please let me know.

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support |  Feedback to us
     
  • Saturday, January 14, 2012 12:36 AM
     
    65 Points
     
     
       Has Code
    Sign In to Vote
    0

    Hi Yi,

    I used your files and still does not work. My environment is W7 64bit, VS2010 SP1. I do not even see the message(assuming the message will come in the output window).

     

    Thanks

    Chandra

    My VCXProj:

     

    <?xml version="1.0" encoding="utf-8"?>
    <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ItemGroup Label="ProjectConfigurations">
        <ProjectConfiguration Include="Debug|Win32">
          <Configuration>Debug</Configuration>
          <Platform>Win32</Platform>
        </ProjectConfiguration>
        <ProjectConfiguration Include="Release|Win32">
          <Configuration>Release</Configuration>
          <Platform>Win32</Platform>
        </ProjectConfiguration>
      </ItemGroup>
      <PropertyGroup Label="Globals">
        <ProjectGuid>{2A75CB1A-378C-4806-B088-09EFFBA2F499}</ProjectGuid>
        <Keyword>Win32Proj</Keyword>
        <RootNamespace>TestProps</RootNamespace>
      </PropertyGroup>
      <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
        <ConfigurationType>DynamicLibrary</ConfigurationType>
        <UseDebugLibraries>true</UseDebugLibraries>
        <CharacterSet>Unicode</CharacterSet>
      </PropertyGroup>
      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
        <ConfigurationType>DynamicLibrary</ConfigurationType>
        <UseDebugLibraries>false</UseDebugLibraries>
        <WholeProgramOptimization>true</WholeProgramOptimization>
        <CharacterSet>Unicode</CharacterSet>
      </PropertyGroup>
      <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
      <ImportGroup Label="ExtensionSettings">
      </ImportGroup>
      <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
        <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
      </ImportGroup>
      <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
        <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
      </ImportGroup>
      <PropertyGroup Label="UserMacros" />
      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
        <LinkIncremental>true</LinkIncremental>
      </PropertyGroup>
      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
        <LinkIncremental>false</LinkIncremental>
      </PropertyGroup>
      <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
        <ClCompile>
          <PrecompiledHeader>Use</PrecompiledHeader>
          <WarningLevel>Level3</WarningLevel>
          <Optimization>Disabled</Optimization>
          <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;TESTPROPS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
        </ClCompile>
        <Link>
          <SubSystem>Windows</SubSystem>
          <GenerateDebugInformation>true</GenerateDebugInformation>
        </Link>
      </ItemDefinitionGroup>
      <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
        <ClCompile>
          <WarningLevel>Level3</WarningLevel>
          <PrecompiledHeader>Use</PrecompiledHeader>
          <Optimization>MaxSpeed</Optimization>
          <FunctionLevelLinking>true</FunctionLevelLinking>
          <IntrinsicFunctions>true</IntrinsicFunctions>
          <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;TESTPROPS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
        </ClCompile>
        <Link>
          <SubSystem>Windows</SubSystem>
          <GenerateDebugInformation>true</GenerateDebugInformation>
          <EnableCOMDATFolding>true</EnableCOMDATFolding>
          <OptimizeReferences>true</OptimizeReferences>
        </Link>
      </ItemDefinitionGroup>
      <ItemGroup>
        <None Include="ReadMe.txt" />
      </ItemGroup>
      <ItemGroup>
        <ClInclude Include="stdafx.h" />
        <ClInclude Include="targetver.h" />
        <ClInclude Include="TestProps.h" />
      </ItemGroup>
      <ItemGroup>
        <ClCompile Include="dllmain.cpp">
          <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
          <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
          </PrecompiledHeader>
          <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</CompileAsManaged>
          <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
          </PrecompiledHeader>
        </ClCompile>
        <ClCompile Include="stdafx.cpp">
          <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
          <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
        </ClCompile>
        <ClCompile Include="TestProps.cpp" />
      </ItemGroup>
      <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
      
      <ImportGroup>
        <Import Project ="test1.props" />
      </ImportGroup>
      
      <Target Name="msg">
        <Message Text=" %(ClCompile.DebugInformationFormat)" />
      </Target>
      
      <ImportGroup Label="ExtensionTargets">
      </ImportGroup>
    </Project>

     

     

    Test1.props:

     

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ImportGroup Label="PropertySheets" />
      <PropertyGroup Label="UserMacros" />
      <PropertyGroup />
      
      <ItemDefinitionGroup>
        <ClCompile>
          <DebugInformationFormat>OldStyle</DebugInformationFormat>
        </ClCompile>
      </ItemDefinitionGroup>
      <ItemGroup />
    </Project>


     

    • Edited by ChandraP Saturday, January 14, 2012 12:44 AM
    •  
     
  • Monday, January 16, 2012 9:08 AM
    UIS
     
    9,705 Points
    Moderator
     
     
    Sign In to Vote
    0

    Hi ChandraP,

    The "msg" is used to test whether the props changes the compile option.

    You can call  msbuild yourproj.vcxproj /t:msg to execute the msg target only under VS2010 command line prompt. The current value of Debug Information will be printout.

    Cheers,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support |  Feedback to us
     
  • Tuesday, January 17, 2012 2:29 AM
     
    0 Points
     
     
     
    Sign In to Vote
    0

    Hi Yi,

    I have the same requirement. I tried your way. The value will be printed out as expected. But there is only one thing I am confused with. Let's take LinkIncremental as reference. I changed'test1.prop' to update the value of LinkIncremental into true for both debug and release configuration.And the value will be printed out as expected. But when I checked out the property page dialog, the value is still false with release configuration. Is this by design? Which value the compiler will take when I build the project with IDE?

    Thanks,

    Jerry

     
  • Tuesday, January 17, 2012 6:03 AM
    Unisys
     
    155 Points
     
     
      Answered
    Sign In to Vote
    0

    IDE just use vcproj file to display the properties, it doesn't phrase it in deep.

    When building, IDE calls MSBuild, therefore it will be "True" as same as you saw from msbuild command line

     
  • Monday, January 23, 2012 2:59 AM
    UIS
     
    9,705 Points
    Moderator
     
     
    Sign In to Vote
    0

    Hello,

     

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support |  Feedback to us
     
  • Monday, January 23, 2012 6:08 PM
     
    65 Points
     
     
     
    Sign In to Vote
    0

    Yes it works. But it is confusing that we cannot see the changed property values from IDE.

    Thanks

    Chandra

     
  • Tuesday, January 24, 2012 2:15 AM
    UIS
     
    9,705 Points
    Moderator
     
     
    Sign In to Vote
    0

    Hi Chandra,

    As Cherubim said, IDE use the information in vcproj file only to show the property page. Any indirect property from "import" will not be effected on the IDE.

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support |  Feedback to us
     
  • Friday, January 27, 2012 2:01 AM
    UIS
     
    9,705 Points
    Moderator
     
     
    Sign In to Vote
    0

    Hello,

     

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 

    Yi

转载于:https://www.cnblogs.com/songtzu/archive/2013/01/11/2856967.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值