I had this issue crop up while supporting an old website that when I came to publish the website in both Visual Studio 2012 and 2013 I would get the following error:
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.
After trying to set the "Target Location" setting here to a shortened path of "c:\wd" I still had the issue:
After some digging around I found that the fix was in the following file:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Transform\Microsoft.Web.Publishing.AspNetCompileMerge.targets
I changed:
<AspnetCompileMergeIntermediateOutputPath Condition="'$(AspnetCompileMergeIntermediateOutputPath)' == ''">$(IntermediateOutputPath)AspnetCompileMerge\</AspnetCompileMergeIntermediateOutputPath>
to
<AspnetCompileMergeIntermediateOutputPath Condition="'$(AspnetCompileMergeIntermediateOutputPath)' == ''">c:\sp\</AspnetCompileMergeIntermediateOutputPath>
The build then completed as expected