Build Server Error with Multi-Threading: Access is denied.


Most recently and in the past I have encountered this error in running build definitions on TFS 2012:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets (3540): Unable to copy file "C:\BLD\4\Project\Name\Binaries\BinaryFile.dll". Access to the path ' C:\BLD\4\Project\Name\Binaries\BinaryFile.dll is denied.

Which is pretty crazy since, the build service account is the one that setup and created those binaries in the first place. How can it not have access to the file?

The issue arises when you have your build definition multi-threading turned on when it attempts to execute and build two dependency chains at the same time (if your application has two or more dependencies). If those dependency chains have the same referenced assemblies you may experience this ‘access is denied’ issue as one attempts to overwrite the binary a second time on the second dependency chain.

The simplest solution is to disable the multi-threading components of the build definition and force it to build the dependency chains sequential by disabling the appropriate setting in the Process template of the build definition:


Set “MSBuild Multi-Proc” to “False”.

The only side effect is potentially slower build total run time. However, it seems negligible in most of my experiences (perhaps a greater effect on much larger projects that take more time to build).