Website publish failing due to file path being too long
Asked Answered
S

7

41

I am trying to publish a Website project from a vendor that has ridiculously long paths to some of its files. When publishing, the error is:

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.

When I publish, Visual Studio 2012 Update 3 is attempting to write to a temp directory, and the prefix is quite long:

 C:\Users\cuser\AppData\Local\Temp\WebSitePublish\MidasCMS400v9-1580334405\obj\Debug\Package\PackageTmp\

I thought I might be able to redirect VS to a different temporary directory at c:\tem by following this SO answer: Temp path too long when publishing a web site project

I create my publication profile, and as soon as I open it, there is an error indicating that WebPublishMethod is not an element of PropertyGroup. Regardless, I updated the file so it looks like this:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>C:\Sites\MidasPublish</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
    <AspnetCompileMergeIntermediateOutputPath>c:\tem\</AspnetCompileMergeIntermediateOutputPath>
  </PropertyGroup>
</Project>

When I try to publish, I get the a modal box pop-up entitled "File Modification Detected", with the message "The project YourWebsite has been modified outside the environment", and it asks me if I want to reload. In my error list, I continue to get the error about the path being too long, as it is not attempting to use the c:\tem directory I identified.

I need to put this bloody thing onto a server, I am up for any solution that allows me to publish the bloody thing. I don't know much about the Website project template, so please let me know if there is a better way.

Southpaw answered 16/10, 2013 at 18:35 Comment(5)
Hi, did you get any solution of above problem, I am also facing similar problem.Crossgarnet
I'm afraid not, I ended up just removing some of the deeper folders to work around the issue - not ideal!Southpaw
Yeah. I too ended up doing manual xcopy instead of using right mouse click>>publish option.Crossgarnet
Take a look at this answer. It fixed the problem for me.https://mcmap.net/q/392966/-creating-a-targeted-obj-folder-for-a-project-in-visual-studioFick
I got the same error. My issue was related to long file names in the App_Data solution sub-folders. Renaming the files with short names solved the problem for me.Afternoons
C
61

From http://forums.asp.net/t/1944241.aspx?Website+publish+failing+due+to+file+path+being+too+long

Add the following line in default PropertyGroup of web project file.

<IntermediateOutputPath>..\Temp\</IntermediateOutputPath>

You can likely make the above path C:\temp or ......\Temp (as needed to get it as close to root of the drive as possible.

In my case, there was no .csproj or .vbproj (website project file) but there was a website.publishproj file that warns you not to edit it, but I did anyway, and it did the trick.

Cornuted answered 21/11, 2014 at 15:30 Comment(8)
i was searching from where i need to add the tag. Once I recheckd the answer, its there. So i just made it as bold to notice it while reading the first time, Thanks for the update.Laritalariviere
So I recently came across some new, useful information related to this: In Website\App_Data\PublishProfiles, you can edit the .pubxml file created when you have publishing profiles. Within this file, you can create a tag of <aspnetcompilemergeintermediateoutputpath>. This is a better (and more permanent) route than editing the generated website.publishproj file.Cornuted
We run MSBuild from Jenkins. I simply add the following to the command line to get it to work: /p:IntermediateOutputPath=c:\temp\ (note the trailing slash is required).Argon
I know this is an old thread. But this <IntermediateOutputPath>..\Temp\</IntermediateOutputPath> is not working along with PrecompileBeforePublish>True</PrecompileBeforePublish> . Any help would be appreciated.Doddered
By the way, it also works if you put this line in your .csproj.user file! So no need to edit main .csproj file and mess with other programmers in your team and TFS (if you use it).Breakage
The path needs to end with a trailing slashPromise
I added it to my local.pubxml file and it needed a trailing slash.Sinotibetan
In my case i had an API, so i needed to set this line in the file: Release.pubxml. Located under properties->PublishProfiles. Anyways, if you are not sure where to set this line up just do a "search in entired solution" for "PropertyGroup"Incombustible
E
5

While moving the project closer to the root file does work. I found a link to a solution that did work for me. The site also does a great job at discussion the issue as well as the details behind his solution.

Sayed Hashimi's solution to long path issue

EDIT:

To Summarize the provided link:

You can update your publish profile file, which is used by MSBuild, to include a replace rule that will shorten the path of your output when publishing to a web deploy package (Zip file).

For example, let's say publishing using the default profile created by Visual Studio, we get the following paths in the zip file:

archive.xml
Content\C_C\Temp\package\WebApplication1\obj\Release\Package\PackageTmp
Content\C_C\Temp\package\WebApplication1\obj\Release\Package\PackageTmp\bin
Content\C_C\Temp\package\WebApplication1\obj\Release\Package\PackageTmp\bin\WebApplication1.dll
Content\C_C\Temp\package\WebApplication1\obj\Release\Package\PackageTmp\index.html
Content\C_C\Temp\package\WebApplication1\obj\Release\Package\PackageTmp\Web.config
parameters.xml
systemInfo.xml

The trick is to replace all of the path defined after Content with a shorter path. In this particular example, replace the path with "website" in the PackagePath element.

One can edit the publishing profile file (.pubxml) and add the follow lines near the end of the file, just before the Project element is terminated.

<PropertyGroup>
  <PackagePath Condition=" '$(PackagePath)'=='' ">website</PackagePath>
  <EnableAddReplaceToUpdatePacakgePath Condition=" '$(EnableAddReplaceToUpdatePacakgePath)'=='' ">true</EnableAddReplaceToUpdatePacakgePath>
    <PackageDependsOn>
    $(PackageDependsOn);
    AddReplaceRuleForAppPath;
    </PackageDependsOn>
</PropertyGroup>
<Target Name="AddReplaceRuleForAppPath" Condition=" '$(EnableAddReplaceToUpdatePacakgePath)'=='true' ">
  <PropertyGroup>
    <_PkgPathFull>$([System.IO.Path]::GetFullPath($(WPPAllFilesInSingleFolder)))</_PkgPathFull>
  </PropertyGroup>

  <!-- escape the text into a regex -->
  <EscapeTextForRegularExpressions Text="$(_PkgPathFull)">
    <Output TaskParameter="Result" PropertyName="_PkgPathRegex" />
  </EscapeTextForRegularExpressions>

  <!-- add the replace rule to update the path -->
  <ItemGroup>
    <MsDeployReplaceRules Include="replaceFullPath">
      <Match>$(_PkgPathRegex)</Match>
      <Replace>$(PackagePath)</Replace>
    </MsDeployReplaceRules>
  </ItemGroup>
</Target>

Now, the publish profile paths should look something like the following:

archive.xml
Content\website
Content\website\bin
Content\website\bin\WebApplication1.dll
Content\website\index.html
Content\website\Web.config
parameters.xml
systemInfo.xml
Edgy answered 9/1, 2015 at 20:35 Comment(2)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.Snowplow
I like this answer, in that the problem I also observed what not necessarily directly related to the intermediate output, but rather the long path included in the zipped package file. With this, you do not have to change the intermediate output for your entire project, and only affect the publishing of the web deploy package.Pterous
H
4

Thanks to Stelvio, from http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2156195-fix-260-character-file-name-length-limitation , there is a solution :

Well, I found a workaround that ALLOW work with path with more than 260 chars.

Disclaimer: I've tried this trick only on Windows 8 x64 and Visual Studio 2013

So, to make it work I've just create a junction to the folder with the mklink command:

Assume this is the original path: d:\very\very\long\path\to\solution\folder, you can obtain a short link as d:\short_path_to_solution_folder just jaunching this command from a dos shell as administrator: mklink /J d:\short_path_to_solution_folder d:\very\very\long\path\to\solution\folder

change source and destination path to you needs

Best Regards! Stelvio

from this link : http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2156195-fix-260-character-file-name-length-limitation

Heartwood answered 8/5, 2015 at 6:51 Comment(0)
J
0

The answer of Jason Beck worked to me with a small change. To avoid the error "The IntermediateOutputPath must end with a trailing slash." use the "\" at the end of the path: ..\Temp\

Your "CONFIG_PUBLISH_FILE.pubxml" should look like this (The "..." omits other configuration that you file may have): ... ... ..\Temp\ ...

Jackelynjackeroo answered 20/12, 2015 at 17:53 Comment(0)
V
0

At the time of publishing the project, the visual studio compiler checks the size of the files that are part of the project.

So I searched for long names in files. I found and renamed those files.

Did Work perfectly

Vauntcourier answered 5/5, 2017 at 16:42 Comment(0)
S
0

In my case it was because the default legacy string length limitation of windows. This was still set to 256-character limit.

To fix this, from an admin powershell session I ran the following command

New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

I needed to reboot the system for the changes to take effect.

Microsoft reference document link here

Scagliola answered 24/12, 2021 at 17:38 Comment(0)
S
-4

This error comes because of long path name....U just cut your folder from current location to D drive or F drive. suppose your project folder name is "myproject", and you should cut this folder and paste to D drive of F drive,that your current path name will be D:\myproject or F:\myproject. Then you publish again......It will work...

Skell answered 25/7, 2014 at 6:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.