为什么TeamCIty构建失败并显示“因为它正在被另一个进程使用”,它是否并行构建?

时间:2018-10-03 20:18:41

标签: teamcity asp.net-core-2.0

我在服务器上安装了TeamCity,并且我的.Net Core项目偶尔会失败,并显示以下消息。如果TeamCity使用并行构建,那么如何禁用它?或者如何使TeamCity的构建更加稳定?

代码可以在我的开发机上编译,没有任何问题,代码也可以在Azure DevOps Build(又称为Visual Studio Online)中进行编译。

[22:06:31][build] /opt/dotnet/sdk/2.1.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly.
[22:06:31][build] /opt/dotnet/sdk/2.1.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.IO.IOException: The process cannot access the file '/home/tagent3/TeamCityBuildAgent/work/479321994f6f7261/.../Contracts.deps.json' because it is being used by another process.
[22:06:31][build] /opt/dotnet/sdk/2.1.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.IO.FileStream.Init(FileMode mode, FileShare share)
[22:06:31][build] /opt/dotnet/sdk/2.1.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
[22:06:31][build] /opt/dotnet/sdk/2.1.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
[22:06:31][build] /opt/dotnet/sdk/2.1.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.IO.File.Create(String path)
[22:06:31][build] /opt/dotnet/sdk/2.1.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.ExecuteCore()
[22:06:31][build] /opt/dotnet/sdk/2.1.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()
[22:06:31][build] /opt/dotnet/sdk/2.1.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
[22:06:31][build] /opt/dotnet/sdk/2.1.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
[22:06:31]

2 个答案:

答案 0 :(得分:1)

您可以添加MSBuild开关/m:1(或/maxcpucount:1) 它说它应该默认为1,但是我也看到了线程注释,说添加标志解决了一些并行构建问题,所以也许它已经改变了。

文档在这里 https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2017

答案 1 :(得分:0)

我在命令行参数: -v n

中使用参数详细度正常级别解决了此问题