c – MsBuild并行编译和构建依赖项
发布时间:2020-12-16 07:13:31 所属栏目:百科 来源:网络整理
导读:我正在研究一个包含大量项目的大型C解决方案. 其中一些是构建瓶颈,其中dll依赖于另一个需要永久构建的东西. 我有很多CPU要构建,但我不能让MSBuild并行编译(不链接)所有内容,只在链接时使用依赖项. 我基本上想拥有每个项目: # build objectsmsbuild /t:Build
我正在研究一个包含大量项目的大型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)',',"(.*.vcxproj)"').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"/> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |