【问题标题】:The "GenerateBindingRedirects" task failed unexpectedly. The specified path, file name, or both are too long“GenerateBindingRedirects”任务意外失败。指定的路径、文件名或两者都太长
【发布时间】:2016-04-15 08:15:43
【问题描述】:

“GenerateBindingRedirects”任务意外失败。

System.IO.PathTooLongException: 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.
   at System.IO.PathHelper.GetFullPathName()
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)
   at System.Xml.XmlWriterSettings.CreateWriter(String outputFileName)
   at System.Xml.XmlWriter.Create(String outputFileName, XmlWriterSettings settings)
   at System.Xml.Linq.XDocument.Save(String fileName, SaveOptions options)
   at Microsoft.Build.Tasks.GenerateBindingRedirects.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() Incryptex.OMS.Workflow.MarketData.Service

【问题讨论】:

  • 这是一个预期的问题 - 因为它说完整的文件路径必须是
  • 完全限定的文件名必须少于260个字符,目录名必须少于248个字符。它在说明问题。
  • 我不认为文件夹名称会造成问题,因为我的一个名为“Incryptex.OMS.Workflow.ExchangeEngine.Workers.Tests”的类库项目工作正常并且构建成功。但是“Incryptex.OMS.Workflow.MarketData.Service”项目给出了错误。如果我们比较项目文件夹名称或目录,则给出错误的文件的字符数少于。
  • 也许this answer 可以帮助你:

标签: c#


【解决方案1】:

最简单的解决办法是:

  1. 卸载出现问题的项目的.csproj 文件。
  2. .csproj文件的末尾添加这个

    <Target Name="WorkaroundAppConfigPathTooLong"
      BeforeTargets="GenerateBindingRedirects">
      <PropertyGroup>
        <_GenerateBindingRedirectsIntermediateAppConfig>$(IntermediateOutputPath)$(TargetFileName).config</_GenerateBindingRedirectsIntermediateAppConfig>
      </PropertyGroup>
    </Target>
    
  3. 保存并重新加载项目。重建。

您基本上是在要求 Visual Studio 缩短给您带来问题的中间应用配置文件的路径长度。

【讨论】:

    【解决方案2】:

    此问题专门与 GenerateBindingRedirects 相关,并在此处进行跟踪:https://github.com/Microsoft/msbuild/issues/1786

    看起来即使是 MAX_PATH 的三分之一的项目名称也可以触发此异常。我有一个名称为 55 个字符的项目。根据上面链接的问题,该项目名称被附加了三次,并添加到完整的项目位置,以创建配置文件的名称。

    对我来说,解决方案是确保我的解决方案的路径少于 70 个字符。

    【讨论】:

      【解决方案3】:

      当您的应用程序中有任何包含超过 259 个字符的文件夹路径时,就会出现此问题。

      我在我的 .Net Core 1.0 应用程序中遇到了这个问题。问题是,我开始使用 NODEJS 的精简服务器以及其他一些 .JS 库包来设计 UI,这只是为了快速启动它不会进入我的电脑以外的任何其他环境。因此,我使用 NPM 将这些库 + lite 服务器组件安装到我的 wwwroot 中。通过 NPM 安装包时,它创建了一个名为 node_modules 的文件夹和一堆其他子文件夹树。

      由于这堆大路径文件夹,我收到了这个错误。问题不在于您的命名空间完全限定名称,问题在于您的项目具有的文件夹。

      我从我的项目中删除了 node_module 文件夹,它编译得很好。另一件事,当使用dotnet build 通过控制台编译时,我没有收到任何错误,只有在通过 IDE 时。

      我在从我的 PC 中删除 node_module 时遇到了一些问题,因为 windows 抛出了相同的异常,实际上这对于 windows 用户来说是一个非常知名的异常。在用长文件夹路径做其他事情时,我多次遇到这种情况。

      无论如何,我尝试了del folder_path 命令,Remove-Item folder_path 没有一个工作,我发现 NPM 有一个名为 rimraf 的包可以完成这项工作,还有另一个工具命名为 7zip (我没有测试)应该做同样的事情。

      所以,使用 NPM,运行 -> npm install -g rimraf 而不是 rimraf folder_path 和快乐的日子 :)

      希望对你有帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多