Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild Managed vs Unmanaged property

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 (usually just version information) differently depending on whether the code is managed or unmanaged.

like image 477
Eric Kulcyk Avatar asked Sep 17 '14 17:09

Eric Kulcyk


1 Answers

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:

<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 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.

like image 159
stijn Avatar answered Sep 22 '22 18:09

stijn