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

Mis*_*pic 29 asp.net msbuild visual-studio visual-studio-2012

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

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.
Run Code Online (Sandbox Code Playgroud)

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

 C:\Users\cuser\AppData\Local\Temp\WebSitePublish\MidasCMS400v9-1580334405\obj\Debug\Package\PackageTmp\
Run Code Online (Sandbox Code Playgroud)

我想我可以c:\tem通过遵循这个SO答案将VS重定向到另一个临时目录:发布网站项目时临时路径太长

我创建了我的发布配置文件,一旦打开它,就会出现一个错误,表明它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>
Run Code Online (Sandbox Code Playgroud)

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

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

Jas*_*eck 45

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

在Web项目文件的默认PropertyGroup中添加以下行.

<IntermediateOutputPath>..\Temp</IntermediateOutputPath>
Run Code Online (Sandbox Code Playgroud)

您可以使用上面的路径C:\ temp或......\Temp(根据需要使其尽可能靠近驱动器的根目录).

在我的情况下,没有.csproj或.vbproj(网站项目文件),但有一个website.publishproj文件,警告你不要编辑它,但我做了反正,它做了伎俩.

  • 我们从Jenkins运行MSBuild.我只需将以下内容添加到命令行以使其工作:/ p:IntermediateOutputPath = c:\ temp \(注意需要使用尾部斜杠). (4认同)

Kra*_*bse 5

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

Sayed Hashimi 解决长路径问题的方法

编辑:

总结提供的链接:

您可以更新 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
Run Code Online (Sandbox Code Playgroud)

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

人们可以编辑发布配置文件 (.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>
Run Code Online (Sandbox Code Playgroud)

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

archive.xml
Content\website
Content\website\bin
Content\website\bin\WebApplication1.dll
Content\website\index.html
Content\website\Web.config
parameters.xml
systemInfo.xml
Run Code Online (Sandbox Code Playgroud)