Temp path too long when publishing a web site project

23,228

Solution 1

Add this to your publish profile to modify the temporary directory for package/publish:

<AspnetCompileMergeIntermediateOutputPath>c:\shortPath\</AspnetCompileMergeIntermediateOutputPath>

Solution 2

  1. Go to your web project folder, navigate to Properties\PublishProfiles folder.
  2. open your profile file profile_name.pubxml (not the profile_name.pubxml.user)
  3. copy/past <AspnetCompileMergeIntermediateOutputPath>c:\shortPath\</AspnetCompileMergeIntermediateOutputPath> under the <PropertyGroup> tag
  4. save your file, you would be able to publish your website using this profil

Solution 3

This is sort of an aside answer, but I ran into this problem when trying to MSBuild a solution that depended on nodeJS and gulp. The problem was that the gulp dependency tree became very deep and the aspnet_compiler was trying to copy that tree to a deeper directory, resulting in this error. I tried everything noted in here but nothing worked.

As it so happened, I was building with TFS, so my solution was to run an attrib +h node_modules\* /S /D before msbuild to hide the directory tree and then attrib +h node_modules\* /S /D. That did it for me.

Sure would be nice if the error thrown in this situation by the compiler revealed the path that caused the write to fail...

Solution 4

try adding this

<IntermediateOutputPath>..\Temp</IntermediateOutputPath>

to the default <propertyGroup />

Solution 5

None of the other answers worked for me.

Visual Studio 2013 Community Edition.

I changed the TMP and TEMP environment variable to a short folder name and it worked.

Share:
23,228
Britton
Author by

Britton

#SOreadytohelp

Updated on March 05, 2020

Comments

  • Britton
    Britton about 4 years

    I am trying to publish an ASP.NET web site project using the Publish Web Site tool but get this error:

    ASPNETCOMPILER(0,0): Error ASPRUNTIME: 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.

    I see that it is trying to copy the files to a very long path in AppData:

    Copying all files to temporary location below for package/publish:
    
    C:\Users\imx0\AppData\Local\Temp\1\WebSitePublish\BMW.Web-424993535\obj\Debug\AspnetCompileMerge\Source.
    
    c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /BMW.Web -p C:\Users\imx0\AppData\Local\Temp\1\WebSitePublish\BMW.Web-424993535\obj\Debug\AspnetCompileMerge\Source C:\Users\imx0\AppData\Local\Temp\1\WebSitePublish\BMW.Web-424993535\obj\Debug\AspnetCompileMerge\TempBuildDir
    

    I couldn't find anything about this temp directory in my .pubxml publish profile. How can I change the temporary directory that Visual Studio copies the files to?

  • Mister Epic
    Mister Epic over 10 years
    Where did you find this out? I tried to implement this fix, but I'm not having much luck: stackoverflow.com/questions/19411136/…
  • Britton
    Britton over 10 years
    @ChrisHardie I found it digging around in the MSBuild installation. For me this was C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.5\Web\Transform. I also get the error about WebPublishMethod being invalid but it works anyway.
  • Stealth Rabbi
    Stealth Rabbi about 10 years
    Where is the "publish profile"? I don't see this in my csproj file at all.
  • Britton
    Britton about 10 years
    @StealthRabbi I was working with a web site which doesn't have a csproj file so it put the publish profile in App_Data. However, I looked at a csproj file for an MVC app and it looks like you might be able to copy that tag into the <PropertyGroup> for each build config.
  • Tarık Özgün Güner
    Tarık Özgün Güner almost 9 years
    Yeah. I think this is the best solution. And dont forget reset your computer after doing that.
  • Aleksey L.
    Aleksey L. over 8 years
    Used this solution for another problem, but also worked great. I've created a "symbol link" to original temp folder and used it in env variables
  • dmarlow
    dmarlow about 8 years
    I too followed this, but decided it was sufficient to just do the node directory. So, doing this attrib +h node_modules before and attrib -h node_modules after.
  • andreasnico
    andreasnico about 8 years
    Wow, this solved it for me! I was trying to compile my views and got the error. This is what I added in my .csproj file: <Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'"> <Exec Command="attrib node_modules +h"/> <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" /> <Exec Command="attrib node_modules -h"/> </Target>
  • Sentinel
    Sentinel almost 8 years
    How on Earth did you discover that?!
  • Rita Chavda
    Rita Chavda over 7 years
    This is change only temp copy path, but copied to path remain same in my project. What will I do?
  • Tigran
    Tigran almost 7 years
    Beautiful solution. Thank you
  • HMcompfreak
    HMcompfreak about 3 years
    I was stuck for quite long as my solution used to publish and all of a sudden it started throwing me length error. This solution worked for me, just I had to append an extra backslash after '.. \Temp\' as it threw error and stated to do so on publish.
  • Richardissimo
    Richardissimo almost 3 years
    This worked for me; but @kennydust, it's worth saying that this change needs to be done in the project file (as covered in stackoverflow.com/questions/19411136/…) rather than being in the publish profile file (which looks very similar, and also has a PropertyGroup).
  • Richardissimo
    Richardissimo almost 3 years
    This treats the symptom rather than the cause, so if long files are added in future, this issue will occur again. In our case, the long file names were coming from a "Connected Services" folder (thanks for the long folder name Microsoft), so there is only so much we can change about the file names within there. This answer worked for me: stackoverflow.com/a/27010735/5198140