微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c – MsBuild并行编译和构建依赖项

我正在研究一个包含大量项目的大型C解决方案.

其中一些是构建瓶颈,其中dll依赖于另一个需要永久构建的东西.

我有很多cpu要构建,但我不能让MSBuild并行编译(不链接)所有内容,只在链接时使用依赖项.

我基本上想拥有每个项目:

# build objects
msbuild /t:BuildCompile project.vcxproj

# only Now build/wait for dependencies
msbuild /t:ResolveReferences;BuildLink project.vcxproj

我希望以上工作作为单个构建的一部分(级联到依赖项目).

我一直试图搞乱MSBuild目标构建订单:

<PropertyGroup>
  <BuildSteps>
    SetBuildDefaultEnvironmentvariables;
    SetUserMacroEnvironmentvariables;
    PrepareForBuild;
    InitializeBuildStatus;
    BuildGenerateSources;
    BuildCompile;

    ResolveReferences;

    BuildLink;
  </BuildSteps>
</PropertyGroup>

不起作用,此安装程序中的Resolve Dependencies不构建依赖项目.

有任何想法吗?只有链接器实际上依赖于引用的项目,objs不会.

解决方法

这是一个可能的解决方案:首先通过从解决方文件中“解析”它们来获取所有项目的列表.如果您已经拥有该列表,则不需要.然后为所有项目调用msbuild两次,一次使用BuildCompile目标,然后使用Build目标.我特意选择了Build目标(因为我已经完成了将会跳过编译)因为我不确定你所提出的只调用ResolveReferences和Link目标的解决方案会在所有情况下成功构建,例如它可能会跳过资源编译,跳过自定义构建步骤等

<?xml version="1.0" encoding="utf-8"?>
<Project Toolsversion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
  <ItemGroup>
    <AllTargets Include="BuildCompile;Build" />
  </ItemGroup>
  <Target Name="Build">
    <ReadLinesFromFile File="mysolution.sln">
      <Output TaskParameter="Lines" ItemName="Solution" />
    </ReadLinesFromFile>

    <ItemGroup>
     <AllProjects Include="$([System.Text.RegularExpressions.Regex]::Match('%(Solution.Identity)',',&quot;(.*\.vcxproj)&quot;').Groups[ 1 ].Value)"/>
    </ItemGroup>

    <MSBuild BuildInParallel="true" Projects="@(AllProjects)"
             Properties="Configuration=$(Configuration);Platform=$(Platform)"
             Targets="%(AllTargets.Identity)"/>
  </Target>
</Project>

调用就好

msbuild mybuild.proj /p:Configuration=Debug;Platform=Win32

我很想知道这是否会改善你的构建时间.

编辑,因为你看到完全重建的外观,也许BuildCompile目标只有在BuildSteps的其他目标运行时才能正常工作.您可以尝试明确地拆分构建:

<MSBuild BuildInParallel="true" Projects="@(AllProjects)"
         Properties="Configuration=$(Configuration);Platform=$(Platform)"
         Targets="SetBuildDefaultEnvironmentvariables;
                  SetUserMacroEnvironmentvariables;
                  PrepareForBuild;
                  InitializeBuildStatus;
                  BuildGenerateSources;
                  BuildCompile;"/>

<MSBuild BuildInParallel="true" Projects="@(AllProjects)"
         Properties="Configuration=$(Configuration);Platform=$(Platform)"
         Targets="Build"/>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐