3
假设我有两个耗时的目标,我想并行执行它们。假设一个目标运行单元测试,另一个目标生成一些文档。我试过这个方法:MSBuild中的并行性
root.targets:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Default">
<Target Name="Default">
<MSBuild Projects="$(MSBuildProjectFile)" Targets="RunTests;BuildDocumentation" BuildInParallel="True"/>
</Target>
<Target Name="RunTests">
<Message Text="Running tests"/>
</Target>
<Target Name="BuildDocumentation">
<Message Text="Building documentation"/>
</Target>
</Project>
,然后调用这样的(一个双核的机器上):
msbuild root.targets /m
但我得到这样的输出:
1>Project "C:\Repository\depot\EDG\DEW\branches\dna.dev.br\DnA\client\src\root.targets" on node 1 (default targets).
1>Project "C:\Repository\depot\EDG\DEW\branches\dna.dev.br\DnA\client\src\root.targets" (1) is building "C:\Repository\depot\EDG\DEW\branches\dna.dev.br\DnA\client\src\root.targets" (1:2) on node 1 (RunTests;BuildDocumentation target(s)).
1>RunTests:
Running tests
BuildDocumentation:
Building documentation
从这个和一些谷歌搜索我收集了并行化仅在项目级别发生。因此,我尝试这样做:
root.targets:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Default">
<Target Name="Default">
<MSBuild Projects="test.targets;documentation.targets" BuildInParallel="True"/>
</Target>
</Project>
test.targets:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Default" DependsOnTargets="RunTests"/>
<Target Name="RunTests">
<Message Text="Running tests"/>
</Target>
</Project>
documentation.targets:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Default" DependsOnTargets="BuildDocumentation"/>
<Target Name="BuildDocumentation">
<Message Text="Building documentation"/>
</Target>
</Project>
以同样的方式运行它,我得到:
1>Project "C:\Repository\depot\EDG\DEW\branches\dna.dev.br\DnA\client\src\root.targets" (1) is building "C:\Repository\depot\EDG\DEW\branches\dna.dev.br\DnA\client\src\test.t
argets" (2) on node 1 (default targets).
2>RunTests:
Running tests
2>Done Building Project "C:\Repository\depot\EDG\DEW\branches\dna.dev.br\DnA\client\src\test.targets" (default targets).
1>Project "C:\Repository\depot\EDG\DEW\branches\dna.dev.br\DnA\client\src\root.targets" (1) is building "C:\Repository\depot\EDG\DEW\branches\dna.dev.br\DnA\client\src\docume
ntation.targets" (3) on node 2 (default targets).
3>BuildDocumentation:
Building documentation
因此,目标是并行构建的。
但是为了并行化的目的将目标分隔成单独的文件似乎很笨拙。我在这里错过了什么吗?有没有一种方法可以避免创建额外的目标文件并仍然实现并行性?
是的,我也有一个共享属性文件。事实上,我必须将目标分成新文件*仅用于并行化的目的*尖叫对我来说很笨拙,因为我不会将它们分开。没有技术上的原因,为什么MSBuild无法并行执行目标,即使它们在同一个文件中。它只会导致单独的进程在同一个文件中执行不同的目标,而不是单独的进程在不同的文件中执行不同的目标。 – cantloginfromwork 2010-11-24 15:03:04