除非我嚴重誤解了MSBuild,否則任務將按它們出現在「目標」節點內的文檔順序執行。如何在MSBuild中並行運行任務
我希望能夠指定兩個任務(如xcopy任務)可以並行運行。我期待着有一個'平行'的任務或...?
除非我嚴重誤解了MSBuild,否則任務將按它們出現在「目標」節點內的文檔順序執行。如何在MSBuild中並行運行任務
我希望能夠指定兩個任務(如xcopy任務)可以並行運行。我期待着有一個'平行'的任務或...?
如上所述,您無法在任務級別甚至目標級別進行並行操作。 MSBuild僅會並行構建項目(即MSBuild項目文件)。因此,您必須使用指定了多個項目的MSBuild task,並且BuildInParallel屬性應設置爲true。還要確保在/ m開關發送的命令行上調用構建時。
賽義德·易卜拉欣·哈希米
的My Book:Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build
我認爲Visual Studio(msbuild)已經並行編譯文件,即使在一個項目中也是如此。 – 2013-09-09 13:13:10
@BaiyanHuang:我認爲這是CL任務能夠並行編譯多個文件,但MSBuild中沒有任何內容允許您自己使用該功能。 – Joey 2014-02-03 11:34:10
我不認爲有一種方法可以做到這一點,而不是使用一些外部工具。我懷疑這是因爲它引入了MS選擇忽略的潛在依賴問題,允許外部工具供應商解決問題(併爲其收取相當多的資金)。
嘗試新的並行任務的MSBuild擴展包 - http://mikefourie.wordpress.com/2012/02/29/executing-msbuild-targets-in-parallel-part-1
這裏是一個方法來並行地運行的MSBuild目標的例子。這個想法是一樣的......將這個msbuild文件本身作爲一個項目來構建。我複製它從我自己的問題:Evaluate item defined in msbuild task via C#
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Build">
<Target Name="Build" DependsOnTargets="PrepareEnvironmentForBuild;MapDrives">
<Exec Command="$(MSBuildBinPath)\msbuild /nologo /clp:Verbosity=quiet $(MSBuildThisFileFullPath) /t:TargetWithConfidentialSteps"/>
<ItemGroup>
<StepsToRunInParallel Include="$(MSBuildThisFileFullPath)">
<Properties>TargetToInvoke=ParallelTarget1</Properties>
</StepsToRunInParallel>
<StepsToRunInParallel Include="$(MSBuildThisFileFullPath)">
<Properties>TargetToInvoke=ParallelTarget2</Properties>
</StepsToRunInParallel>
</ItemGroup>
<MSBuild Projects="@(StepsToRunInParallel)" BuildInParallel="true" StopOnFirstFailure="true" Targets="InvokeInParallelWithinThisProject"/>
</Target>
<Target Name="InvokeInParallelWithinThisProject">
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="$(TargetToInvoke)" StopOnFirstFailure="true"/>
</Target>
<Target Name="ParallelTarget1">
<Message Text="Hello from ParallelTarget1"/>
</Target>
<Target Name="ParallelTarget2">
<Message Text="Hello from ParallelTarget2"/>
</Target>
<Target Name="PrepareEnvironmentForBuild">
<Message Text="Hello from PrepareEnvironmentForBuild"/>
</Target>
<Target Name="MapDrives">
<Message Text="Hello from MapDrives"/>
</Target>
<Target Name="TargetWithConfidentialSteps">
<Message Text="Hush! Verbosity on the wrapper does not affect the Exec call." Importance="High"/>
</Target>
投贊成票:https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/9604311-allow-custom -build-tools-to-run-in-parallel – Trass3r 2016-12-15 12:11:04