"The following path contains more than the allowed 259 characters" on gated build when deleting a file

msbuild, visual-studio-2012

Solution

The trick is to:

- Undo the delete

- Rename the file to a shorter name

- Check-in (triggering the build)

- Get Latest

- Delete the file

- Check-in

Problem

I am using VS 2012 with TFS 2012. I am checking in a set of changes that includes deleting a file with a long combined path/file name. The gated build fails with: ``` Exception Message: TF400889: The following path contains more than the allowed 259 characters: C:\Builds\10\MFirstPartOfMyPath>\__Unmapped__\78118\<SecondPartOfMyPath>\<MyFileName>.sql. Specify a shorter path. (type InvalidPathException) Exception Stack Trace: Server stack trace: at Microsoft.TeamFoundation.Common.FileSpec.GetFullPathWrapper(String path) at Microsoft.TeamFoundation.Common.FileSpec.GetFullPath(String path, Boolean checkForIllegalDollar) at Microsoft.TeamFoundation.VersionControl.Client.Workspace.Map(String serverPath, String localPath) at Microsoft.TeamFoundation.Build.Workflow.Activities.TfWorkfold.RunCommand(VersionControlScope versionControlScope, Workspace workspace, TfWorkfoldAction action, String serverPath, String localPath) at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase) at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData) at System.Action`5.EndInvoke(IAsyncResult result) at Microsoft.TeamFoundation.Build.Workflow.Activities.TfWorkfold.EndExecute(AsyncCodeActivityContext context, IAsyncResult result) at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager) Inner Exception Details: Exception Message: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. (type PathTooLongException) Exception Stack Trace: at System.IO.PathHelper.GetFullPathName() at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength) at System.IO.Path.GetFullPath(String path) at Microsoft.TeamFoundation.Common.FileSpec.GetFullPathWrapper(String path) ``` I could understand this if I were trying to add such a file, but the check-in is trying to delete one that already exists. How can I work around this error?

Original source