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.

+3


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">
  <ItemGroup>
    <ClCompile Include="dummy.cpp" />
  </ItemGroup>

  <PropertyGroup>
    <CompileAsManaged>@(ClCompile->AnyHaveMetadataValue('CompileAsManaged','true'))</CompileAsManaged>
  </PropertyGroup>

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

  <ItemGroup>
    <ClCompile Remove="dummy.cpp" />
  </ItemGroup>
</Target>

      



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.

+1


source


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.



0


source







All Articles