gpt4 book ai didi

msbuild - MSBuild 中的并行性

转载 作者:行者123 更新时间:2023-12-02 15:59:25 31 4
gpt4 key购买 nike

假设我有两个耗时的目标,并且我想并行执行它们。假设一个目标运行单元测试,另一个目标生成一些文档。我尝试过这种方法:

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>

测试目标:

<?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>

文档.目标:

<?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

因此,目标是并行构建的。

但是仅仅为了并行化的目的将目标分离到单独的文件中似乎很笨拙。我在这里错过了什么吗?有没有办法可以避免创建额外的目标文件并仍然实现并行性?

最佳答案

我对耗时的构建做了同样的事情,并且将不同文件中的目标分开对我来说并不显得笨拙。

由于您想并行构建它们,因此它们不会交互。它们是构建的一部分,但除此之外,它们没有理由位于同一个文件中。

我还将properties.xml.Targets中的属性和项目分开,以便更轻松地维护它们。通过这样做,我可以在多个目标文件中引用它们,而无需复制代码。

关于msbuild - MSBuild 中的并行性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4266539/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com