我正在开发一个包含大量项目的大型C ++解决方案。
其中一些是构建瓶颈,其中dll依赖于另一个需要永久构建的文件。
我有很多CPU可以构建,但是我无法让MSBuild并行编译(不链接)所有内容,而只能在链接时使用依赖项。
我本质上想在每个项目上都有:
# build objects
msbuild /t:BuildCompile project.vcxproj
# only now build/wait for dependencies
msbuild /t:ResolveReferences;BuildLink project.vcxproj
Run Code Online (Sandbox Code Playgroud)
我希望以上内容可以作为单个构建的一部分(级联到相关项目)。
我一直在尝试弄乱MSBuild目标构建顺序:
<PropertyGroup>
<BuildSteps>
SetBuildDefaultEnvironmentVariables;
SetUserMacroEnvironmentVariables;
PrepareForBuild;
InitializeBuildStatus;
BuildGenerateSources;
BuildCompile;
ResolveReferences;
BuildLink;
</BuildSteps>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
不起作用,此设置中的“解决依赖关系”不会生成依赖项目。
有任何想法吗?实际上,只有链接器依赖于引用的项目,而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)', ', "(.*\.vcxproj)"').Groups[ 1 ].Value)"/>
</ItemGroup>
<MSBuild BuildInParallel="true" Projects="@(AllProjects)"
Properties="Configuration=$(Configuration);Platform=$(Platform)"
Targets="%(AllTargets.Identity)"/>
</Target>
</Project>
Run Code Online (Sandbox Code Playgroud)
调用类似
msbuild mybuild.proj /p:Configuration=Debug;Platform=Win32
Run Code Online (Sandbox Code Playgroud)
我很好奇这是否会缩短您的构建时间。
编辑,因为您看到的是完全重建的内容,也许 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"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
771 次 |
| 最近记录: |