Website publish failing due to file path being too long

38,881

Solution 1

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.

Solution 2

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

Solution 3

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
Share:
38,881
Mister Epic
Author by

Mister Epic

Updated on December 25, 2021

Comments

  • Mister Epic
    Mister Epic over 2 years

    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.

  • bummi
    bummi over 9 years
    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.
  • kbvishnu
    kbvishnu over 9 years
    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.
  • Jason Beck
    Jason Beck almost 9 years
    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.
  • neoscribe
    neoscribe almost 9 years
    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).
  • Sreekanth Mohan
    Sreekanth Mohan about 8 years
    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.
  • kasparspr
    kasparspr about 8 years
    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).
  • Scott Forbes
    Scott Forbes about 5 years
    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.
  • plr108
    plr108 over 3 years
    The path needs to end with a trailing slash
  • Enkode
    Enkode over 3 years
    I added it to my local.pubxml file and it needed a trailing slash.