MSBuild Managed vs Unmanaged property

Is there a way in MSBuild logic to determine if managed or unmanaged code is running? Not C ++ vs C #, but just managed vs. unmanaged? I would like to set some properties (usually version information) differently depending on whether the code is managed or unmanaged.


source to share

2 answers

Usually in the vcxproj file for managed compilation (afaik), there are at least two things that change in our C ++ / cli property master table used for all cli projects: the property is CLRSupport

set to true and the ClCompile

ItemGroup has metadata CompileAsManaged

set as true. You can check either of these or both. This sets the one that prints the values:

<Target Name="CheckManaged">
    <ClCompile Include="dummy.cpp" />


  <Message Text="CompileAsManaged is $(CompileAsManaged) and CLRSupport is $(CLRSupport)" />

    <ClCompile Remove="dummy.cpp" />


As you can see, getting the metadata value CompileAsManaged

requires some processing: I add the item to the ClCompile group, because if the group is empty, you cannot use CompileAsManaged; usually you can just omit it.



In C ++, every item in ClCompile (list of source files) has a CompileAsManaged

metadata value . Setting properties is tricky as it can vary for each source file, but simpler if you only expect (and support) disabling the project-wide setting. Switch this to the IDE and see what changes in vcxproj. It has several different meanings.



All Articles