MSBuild Managed vs Unmanaged property

前端 未结 2 1446
暖寄归人
暖寄归人 2021-01-18 08:11

Is there a way in MSBuild logic to determine if I am running managed vs unmanaged code? Not C++ vs C#, but just managed vs unmanaged? I\'d like to set some properties (usu

2条回答
  •  野的像风
    2021-01-18 08:52

    There are normally two things that change in a vcxproj file for managed complation (afaik, at least that's how we have it in our master c++/cli property sheet used for all cli projects: the CLRSupport property is set to true and the ClCompile ItemGroup has the CompileAsManaged metadata set to true. You can check on any of these or both. Here's a target which prints the values:

    
      
        
      
    
      
        @(ClCompile->AnyHaveMetadataValue('CompileAsManaged','true'))
      
    
      
    
      
        
      
    
    

    As you can see getting the CompileAsManaged metadata value requires some treatment: I'm adding an item to the ClCompile group because if the group is empty you canot use CompileAsManaged; normally you can just omit this.

提交回复
热议问题