MSBuild托管与非托管属性 [英] MSBuild Managed vs Unmanaged property
问题描述
MSBuild逻辑中是否有一种方法可以确定我运行的是托管代码还是非托管代码?不是C ++ vs C#,而是托管还是非托管?我想根据代码是托管还是非托管设置不同的一些属性(通常只是版本信息).
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.
推荐答案
在vcxproj文件中,通常有两件事会发生变化,以进行托管的合并(afaik,至少这是我们在使用的主c ++/cli属性表中所拥有的方式)对于所有cli项目:CLRSupport
属性设置为true,而ClCompile
ItemGroup的CompileAsManaged
元数据设置为true.您可以检查其中一个或两个.这是一个打印值的目标:>
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>
如您所见,获取CompileAsManaged
元数据值需要一些处理:我将一个项目添加到ClCompile组中,因为如果该组为空,则可以使用CompileAsManaged;通常,您可以忽略它.
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.
这篇关于MSBuild托管与非托管属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!