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