MSBuild CL 任务参数
MSBuild CL Task Parameters
我正在尝试使用 MSBuild 自动编译各种开源项目。
我想向我的编译管道添加自定义 CL.exe 标志:将调用约定设置为 fastcall(在 cl.exe 中,它作为 /Gr 传递)。
这意味着需要覆盖默认的 cdecl 选项 (/Gd)。
我尝试设置 MSBuild 属性 但这没有用:
MSBuild.exe /p:PlatformToolset=v141 /p:Platform=x64 /p:Configuration=Release /p:CallingConvention=/Gr
我还想用其他几个标志来做到这一点,这样这就不会孤立于调用约定。我也希望在不编辑任何配置文件的情况下执行此操作,仅使用 CLI 即可。
如何使用 MSBuild 执行此操作?
谢谢!
I tried setting an MSBuild property but this did not work. How can I
do this with MSBuild?
查看 msbuild Global Properties,命令行仅接收 msbuild 属性,而 CallingConvention
不是 msbuild 属性。
我创建了一个 C++ 项目并在 Debug|X86 配置中更改了 C/C++=>Advanced
中的 /Gd to /Gr
然后我看到了这样的东西:
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
...
<CallingConvention>FastCall</CallingConvention>
</ClCompile>
<Link>
...
</Link>
</ItemDefinitionGroup>
很明显CallingConvention
只是Item
CLCompile
中的一个Metadata
。这不是 msbuild 属性。所以我们不能像这样在msbuild命令行中设置它:msbuild /p:xxx
.
可能的解决方法:
因为使用 /Gr
和 /Gd
之间的唯一区别是元数据行:
所以我认为我们可以在项目文件中复制一份 ItemDefinitionGroup
并将它们的条件设置为:
<!--ItemDefinitionGroup when using default /Gd-->
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32' AND '$(UseFastCall)' == ''">
<ClCompile>
...
</ClCompile>
...
</ItemDefinitionGroup>
<!--ItemDefinitionGroup when using /Gr-->
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32' AND '$(UseFastCall)' != ''">
<ClCompile>
...
<CallingConvention>FastCall</CallingConvention> <!--The only difference here.-->
</ClCompile>
...
</ItemDefinitionGroup>
然后,如果我们将值传递给自定义 属性 UseFastCall
,例如:MSBuild.exe /p:PlatformToolset=v141 /p:Platform=x86 /p:Configuration=Debug /p:UseFastCall=true
。它应该使用 /Gr
元数据。如果我们不向 属性 传递值,它将使用默认值 /Gd
。因此解决方法是创建自定义 属性 来控制该行为。 (仅针对Debug|win32,其他配置可能还需要编辑。)
我正在尝试使用 MSBuild 自动编译各种开源项目。
我想向我的编译管道添加自定义 CL.exe 标志:将调用约定设置为 fastcall(在 cl.exe 中,它作为 /Gr 传递)。 这意味着需要覆盖默认的 cdecl 选项 (/Gd)。
我尝试设置 MSBuild 属性 但这没有用:
MSBuild.exe /p:PlatformToolset=v141 /p:Platform=x64 /p:Configuration=Release /p:CallingConvention=/Gr
我还想用其他几个标志来做到这一点,这样这就不会孤立于调用约定。我也希望在不编辑任何配置文件的情况下执行此操作,仅使用 CLI 即可。
如何使用 MSBuild 执行此操作?
谢谢!
I tried setting an MSBuild property but this did not work. How can I do this with MSBuild?
查看 msbuild Global Properties,命令行仅接收 msbuild 属性,而 CallingConvention
不是 msbuild 属性。
我创建了一个 C++ 项目并在 Debug|X86 配置中更改了 C/C++=>Advanced
中的 /Gd to /Gr
然后我看到了这样的东西:
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
...
<CallingConvention>FastCall</CallingConvention>
</ClCompile>
<Link>
...
</Link>
</ItemDefinitionGroup>
很明显CallingConvention
只是Item
CLCompile
中的一个Metadata
。这不是 msbuild 属性。所以我们不能像这样在msbuild命令行中设置它:msbuild /p:xxx
.
可能的解决方法:
因为使用 /Gr
和 /Gd
之间的唯一区别是元数据行:
所以我认为我们可以在项目文件中复制一份 ItemDefinitionGroup
并将它们的条件设置为:
<!--ItemDefinitionGroup when using default /Gd-->
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32' AND '$(UseFastCall)' == ''">
<ClCompile>
...
</ClCompile>
...
</ItemDefinitionGroup>
<!--ItemDefinitionGroup when using /Gr-->
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32' AND '$(UseFastCall)' != ''">
<ClCompile>
...
<CallingConvention>FastCall</CallingConvention> <!--The only difference here.-->
</ClCompile>
...
</ItemDefinitionGroup>
然后,如果我们将值传递给自定义 属性 UseFastCall
,例如:MSBuild.exe /p:PlatformToolset=v141 /p:Platform=x86 /p:Configuration=Debug /p:UseFastCall=true
。它应该使用 /Gr
元数据。如果我们不向 属性 传递值,它将使用默认值 /Gd
。因此解决方法是创建自定义 属性 来控制该行为。 (仅针对Debug|win32,其他配置可能还需要编辑。)