Team Build and the 260 character path limitation

When doing automated builds you may encounter one of the following error messages:

  • error MSB3021: Unable to copy file...
  • TF10128... contains more than the allowed 259 characters.
    Or
  • CS0006: Metadata file .dll could not be found

In Aaron Hallberg's post he explains these errors as being due to a windows limitation that file paths cannot exceed 260 characters.  He also explains how the absolute paths of files may easily end up approaching this limit in an automated build, whilst being well under the limit when built normally.

However, what he doesn't mention is that MSBuild can encounter the 260 character limitation in builds with absolute file paths well under the 260 character limit (including the automated build directories).  As noted in this post the absolute path length limit that can produce CS006 may seem to vary from one solution to the next.

The reason for this lies in the way MSBuild builds assemblies which reference other assemblies using file references.  See this page for a good explanation about different types of references you may have in a Visual Studio project.

When compiling a project with file references, MSBuild generates a path to a (file) referenced assembly by concatenating the relative path of the referenced assembly from the project to the absolute project directory path of the project.  So for example the absolute path to an assembly you need to reference may only be 129 characters e.g.

C:\Standard Libraries\Mobile\Compact Framework\Windows Dynamic Mobile Framework\Microsoft.Dynamics.Mobile.Framework.Controls.dll

However it's relative path from a project referencing this assembly may be significantly longer e.g

..\..\..\..\..\..\..\Standard Libraries\Mobile\Compact Framework\Windows Dynamic Mobile Framework\Microsoft.Dynamics.Mobile.Framework.Controls.dll

... which is 147 characters long.  The absolute path of the project containing this file reference, might only be 94 characters e.g.

C:\Company\Division\System\Software\Mobile Forms\Controls\Inventory\InventoryManagement.csproj

But when built using the TFS automated build system it might end up being well over 141 characters long e.g.

C:\BuildLocation\Framework Projects\NightlyBuild\Company\Division\System\Software\Mobile Forms\Controls\Inventory\InventoryManagement.csproj

In this case when compiling this project, MSBuild will generate a path to the referenced assembly as follows:

C:\BuildLocation\Framework Projects\Nightly Build\Company\Division\System\Software\Mobile Forms\Controls\Inventory\..\..\..\..\..\..\..\Standard Libraries\Mobile\Compact Framework\Windows Dynamic Mobile Framework\Microsoft.Dynamics.Mobile.Framework.Controls.dll

This path exceeds the windows 260 character limit and will result in a CS0006 error.

Published: Sunday, March 02, 2008 10:00 AM by Michael Lang
Filed under: DevTools
Kick it

Comments

RE: Team Build and the 260 character path limitation

Published: Tuesday, December 01, 2009 3:24 PM by geeks
Nice post,

keep up the good work,

Thanks for writing about it

Leave a comment

Your Name (required):
Your Url (optional):
Title (required):
Your Comment (required):

MBLM Logic Check - Protection from spiders and scripts

Guarding against malicious attacks on the web is an unfortunate necessity. To prove your request is authentic, provide answer to the question below.

Enter the answer in numerical format e.g. Q: two + two A: 4
What is seventeen minus twenty
 

Home

Microsoft.NET services, software and development resources