由于文件路径太长,网站发布失败

时间:2013-10-16 18:35:47

标签: asp.net visual-studio visual-studio-2012 msbuild

我正在尝试从供应商发布一个网站项目,该供应商的某些文件路径非常长。发布时,错误是:

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.

当我发布时,Visual Studio 2012 Update 3正在尝试写入临时目录,并且前缀很长:

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

我想我可以通过以下SO回答将VS重定向到c:\tem的其他临时目录:Temp path too long when publishing a web site project

我创建了我的发布配置文件,一旦打开它,就会出现错误,指示WebPublishMethod不是PropertyGroup的元素。无论如何,我更新了文件,看起来像这样:

<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>

当我尝试发布时,我收到一个名为“检测到文件修改”的模式框弹出窗口,其中显示消息“项目YourWebsite已在环境外修改”,并询问我是否要重新加载。在我的错误列表中,我继续得到关于路径太长的错误,因为它没有尝试使用我识别的c:\tem目录。

我需要将这个血腥的东西放到服务器上,我想要任何允许我发布血腥事物的解决方案。我对网站项目模板了解不多,所以如果有更好的方法,请告诉我。

7 个答案:

答案 0 :(得分:44)

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

在网络项目文件的默认 PropertyGroup 中添加以下行。

<IntermediateOutputPath>..\Temp</IntermediateOutputPath>

您可以将上述路径设置为C:\ temp或...... \ Temp(根据需要使其尽可能靠近驱动器的根目录。

在我的情况下,没有.csproj或.vbproj(网站项目文件),但是有一个website.publishproj文件警告你不要编辑它,但我还是做了,它确实做到了。

答案 1 :(得分:3)

感谢来自http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2156195-fix-260-character-file-name-length-limitation的Stelvio,有一个解决方案:

好吧,我找到了一个解决方法,允许使用超过260个字符的路径。

免责声明:我在Windows 8 x64和Visual Studio 2013上尝试过这个技巧

所以,为了使它工作,我只是使用mklink命令创建一个到文件夹的联结:

假设这是原始路径:d:\ very \ very \ long \ path \ to \ solution \ folder,您可以获得一个简短的链接,如d:\ short_path_to_solution_folder,只需从DOS shell中以管理员身份执行此命令: mklink / J d:\ short_path_to_solution_folder d:\ very \ very \ long \ path \ to \ solution \ folder

更改您需要的源和目标路径

最诚挚的问候! 斯泰尔维奥

从这个链接: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2156195-fix-260-character-file-name-length-limitation

答案 2 :(得分:2)

将项目移近根文件确实有效。我找到了一个对我有用的解决方案的链接。该网站在讨论问题以及解决方案背后的细节方面也做得很好。

Sayed Hashimi's solution to long path issue

编辑:

总结提供的链接:

您可以更新MSBuild使用的发布配置文件,以包含替换规则,该规则将在发布到Web部署包(Zip文件)时缩短输出路径。

例如,让我们说使用Visual Studio创建的默认配置文件进行发布,我们在zip文件中获得以下路径:

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

诀窍是用更短的路径替换Content之后定义的所有路径。在此特定示例中,将路径替换为&#34; website&#34;在PackagePath元素中。

可以编辑发布配置文件(.pubxml)并在文件末尾附近添加跟随行,就在Project元素终止之前。

<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>

现在,发布配置文件路径应如下所示:

archive.xml
Content\website
Content\website\bin
Content\website\bin\WebApplication1.dll
Content\website\index.html
Content\website\Web.config
parameters.xml
systemInfo.xml

答案 3 :(得分:0)

Jason Beck的答案对我有所改变。为了避免错误,“IntermediateOutputPath必须以尾部斜杠结束。”#34;使用&#34; \&#34;在路径的尽头: .. \温度\

你的&#34; CONFIG_PUBLISH_FILE.pubxml&#34;应该是这样的(&#34; ...&#34;省略您提交的其他配置): ...        ...     .. \ TEMP \     ...   

答案 4 :(得分:0)

在发布项目时,visual studio编译器会检查属于项目的文件的大小。

所以我搜索文件中的长名称。 我找到并重命名了这些文件。

完美的工作

答案 5 :(得分:0)

这个问题的简单解决方案是,文件夹有短名称,文件夹内没有太多文件夹,我的意思是保持文件夹层次结构简单,你将摆脱这个错误

答案 6 :(得分:-4)

此错误是因为路径名称较长....刚刚将您的文件夹从当前位置剪切到D盘或F盘。假设你的项目文件夹名称是“myproject”,你应该剪切这个文件夹并粘贴到F盘的D盘,你当前的路径名是D:\ myproject或F:\ myproject。然后你再次发布......它会工作......

相关问题