Meaning of numbers in left column of output pane in Visual Studio when building

时间:2016-10-20 19:11:36

标签: visual-studio visual-studio-2015 build

I've wondered for years as to what is the meaning of numbers in the left column of the output pane in Visual Studio when doing a build. The generally increase as each project in the solution gets built, but they also jump around as well. For example:

1>------ Rebuild All started: Project: MyCompany.MyProject1, Configuration: Debug Any CPU ------
2>------ Rebuild All started: Project: MyCompany.MyProject2, Configuration: Debug Any CPU ------
3>------ Rebuild All started: Project: MyCompany.MyProject3, Configuration: Debug Any CPU ------
4>------ Rebuild All started: Project: MyCompany.MyProject4, Configuration: Debug Any CPU ------
4>C:\SourcePath\MyApplication\MyNamespace\Views\MyFeature\MyCompany.MyProject2.csproj(172,3): warning MSB4011: "C:\MyPath1.CSharp.targets" cannot be imported again. It was already imported at "C:\MyPath2\MyCompany.Build.CustomAfterMicrosoftCSharpTargets.props (41,5)". This is most likely a build authoring error. This subsequent import will be ignored. 
4>  Restoring NuGet packages...
4>  To prevent NuGet from downloading packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download missing packages'.
4>  Feeds used:
4>    C:\Users\MyUser\AppData\Local\NuGet\Cache
4>    C:\Users\MyUser\.nuget\packages\
4>    https://api.nuget.org/v3/index.json
4>    http://nuget.MyCompany.com/nuget/api/v2/
4>    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
4>  
4>  All packages listed in MyPath5\packages.config are already installed.
4>  MyCompany.MyProject4 -> MyPath6\MyCompany.MyProject4.dll
5>------ Rebuild All started: Project: MyCompany.MyNamespace.This.Something, Configuration: Debug Any CPU ------
5>  MyCompany.MyNamespace.This.Something -> C:\SourcePath\MyApplication\MyNamespace\ThisLayer\Something\bin\Debug\MyCompany.MyNamespace.This.Something.dll
3>C:\SourcePath\MyApplication\MyNamespace\Views\MyFeature\MyCompany.MyProject2.csproj(172,3): warning MSB4011: "C:\MyPath1.CSharp.targets" cannot be imported again. It was already imported at "C:\MyPath2\MyCompany.Build.CustomAfterMicrosoftCSharpTargets.props (41,5)". This is most likely a build authoring error. This subsequent import will be ignored. 
3>  Restoring NuGet packages...

1 个答案:

答案 0 :(得分:3)

在构建开始时,Visual Studio会为您要构建的每个项目分配一个唯一的编号,直到达到最大数量,我将在一秒钟内解释。在您的情况下,这些是您看到的前四行:X>------ Rebuild All started

现在VS(及其配套的MSBuild)尝试解决项目之间的依赖关系。然后,它将项目分组为必须依次顺序构建的单元,因为它们相互依赖。但是这些组织本身并没有任何依赖关系,因此可以并行编译而不会相互影响。

可以在Tools --> Options --> Project and Solutions --> Build and Run --> maximum number of parallel project builds下的VS中更改最大并行构建数。在我的情况下,默认值是4个并行构建,但它的documented个人默认值是CPU核心数,它只影响C#和C ++项目,当前最大数量为32 (我不知道这是否意味着逻辑或物理核心,但逻辑核心对我来说最有意义。)

输出窗口中每行开头的每个数字现在都属于已分配给此数字的项目的构建进度。

因此,在您的情况下MyCompany.MyProject4首先(很可能是纯随机的)构建,所有以4>开头的行都属于该项目。完成后,VS决定使用此空闲插槽并将另一个项目MyCompany.MyNamespace.This.Something添加到构建过程中,并为其分配编号5>

它开始构建这个项目,但突然之间,编号为MyCompany.MyProject3的项目3>的构建最终取得了一些进展并打印了它的构建消息。

因此,数字的混乱实际上是四个并行线程的结果,这些线程在它们发生时打印它们的输出。实际上,这些线程中的每一个实际上都是一个独立的MSBuild.exe进程,您可以在Windows任务管理器中看到它。

如果你的所有项目都只有一个项目依赖项(并且每个项目只引用一次),那么如果你将它们组合在一起,你就永远不会看到并行构建,因为那里没有什么可以安全地同时完成。 (你不能依赖尚未建成的东西。)

您可以在documentation of Visual Studiodocumentation of MSBuild中找到有关并行构建的更详细信息。