2

I am running an MSbuild task for my solution (with many projects) on Azure Devops but the build failed at some steps named _CopyFilesMarkedCopyLocal and (_CopyFilesMarkedCopyLocal target).

At these steps, the build attempted to create a 'bin/debug' folder before doing the copy but this failed with the error codes MSB3021, MSB3026 and MSB3027. Here's a part of my log file where this issue occurs.

##_CopyFilesMarkedCopyLocal:
  Creating directory "bin\Debug".
  Creating directory "bin\Debug".
  Creating directory "bin\Debug".
  Creating directory "bin\Debug

##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(4384,5): Error MSB3027: Could not copy "d:\a\1\s\WWSS\packages\CrystalDecisions.Windows.Forms.1.0.0\lib\CrystalDecisions.Windows.Forms.dll" to "bin\Debug\CrystalDecisions.Windows.Forms.dll". Exceeded retry count of 10. Failed. 

##[d:\a\1\s\my\project\path\M1.csproj]

The content of my yaml file is:

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/Mach1.sln'
    feedsToUse: 'select'
    vstsFeed: '93d16ac6-dhfjjj-43cb-89d5-e6a-41d0-b752-khf0e84jbf'


- task: MSBuild@1
  inputs:
    solution: '**/Mach1.sln'
    msbuildArchitecture: 'x64'
    platform: 'Any CPU'
    configuration: 'Debug' 

The solutions I found after searching for those error codes were only for scenarios where the files to be copied were locked, but not where the bin/debug folder already exists. From the build log, similar _CopyFilesMarkedCopyLocal steps on some projects in the solution ran successfully but I can't explain why it failed in other places.

I need a way to make the build continue even when the bin/debug folder already exists but I don't know where to make this setting.

Some of the links I've visited are listed below but none has been helpful

James Z
  • 12,209
  • 10
  • 24
  • 44
Yusuff Sodiq
  • 815
  • 2
  • 12
  • 19
  • Hi, what's the result if you use [Visual Studio build task](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/visual-studio-build?view=azure-devops), see [this](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/msbuild?view=azure-devops#should-i-use-the-visual-studio-build-task-or-the-msbuild-task), since you're building whole solution. Also, apart from the MSB3073, could you share some details about msb3021 and msb3026 to help trouble-shooting :) – LoLance Jan 06 '20 at 01:45
  • Hi Yusuff, do you use Microsoft-hosted agent or private agent? And could you please share the detailed log(System.Debug=true) of failed msbuild task by [this](https://filebin.net/) and share the url to me, so that I can check it directly for you. (Note: Delete the personal data if it exists!) – LoLance Jan 06 '20 at 07:14
  • I also used the visual studio build task and the result was the same. I'm running the build on Azure Devops with Microsoft-hosted agent. – Yusuff Sodiq Jan 22 '20 at 22:25
  • Thanks for the info above, I tried several tests but still can't reproduce this issue in my machine. Have you met same issue if you create a new project in VS and publish it to Devops to build? I guess this issue has something to do with your xx.sln file and xx.csproj files. Especially csproj files, could you share the content of your project file here or in your question? So that I can check for you directly:) – LoLance Jan 24 '20 at 06:16
  • I agree it may have to do with my csproj or sln files. The issue only happens with this pipeline because I have another pipeline connected to a different repo, runs the VSBuild task and this works well. In addition, it's surprising that this repo which fails here runs fine on Teamcity. Please check the csproj file [here](https://pastebin.com/MJTmR0Qn) to see if you can get more insights. Thanks – Yusuff Sodiq Jan 24 '20 at 21:00
  • Sorry but I can't access your project file by that link, it displays `This is a private paste. If you created this paste, please login to view it.` Could you share it in question or in one public github repo? – LoLance Jan 27 '20 at 07:42
  • @LanceLi-MSFT I'm sorry about that, I just made it public – Yusuff Sodiq Jan 27 '20 at 13:41

2 Answers2

0

I need a way to make the build continue even when the bin/debug folder already exists but I don't know where to make this setting.

_CopyFilesMarkedCopyLocal target is not something responsible for creating bin\Debug folder. Instead PrepareForBuild target is responsible for doing that:

enter image description here

So your issue could result from something wrong about the PrepareForBuild target which runs before _CopyFilesMarkedCopyLocal target. I'm not sure about the exact cause(debug folder locked or files inside it occupied?) of your issue with the info above.

As a temporary workaround with info above you can try:

1.Add msbuildArguments: '/p:OutputPath=mybin\Debug' to overcome your current output path, output your built assemblies to mybin\Debug instead of bin\Debug to avoid the issue occurs when bin\Debug is locked or occupied.

2.Use newer VS build task instead of old msbuild task. As document suggests:

enter image description here

LoLance
  • 25,666
  • 1
  • 39
  • 73
0

After trying so many options, what finally fixed the issue for me was checking the "Build in Parallel" checkbox in the Advanced options of the VSBuild task.

I don't know why this fixed it but it could have saved me days of efforts if I had known.

And just to confirm, I used the MSBuild task also with the "Build in Parallel" option selected and the build ran successfully and took relatively the same amount of time.

Yusuff Sodiq
  • 815
  • 2
  • 12
  • 19