c# - "GenerateBindingRedirects"任务意外失败。指定的路径、文件名或两者都太长

标签 c#

“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

最佳答案

最简单的解决方案是:

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

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

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

关于c# - "GenerateBindingRedirects"任务意外失败。指定的路径、文件名或两者都太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36641775/

相关文章:

c# - 使用 int 键时输入字符串的格式错误

c# - 为什么这个按钮的 OnClick 事件只工作一次?

c# - 来自 REST 的 Xamarin 图像

c# - 代码在运行多次后切断字符串

c# - EF v1 的加载行为?

c# - 前面的类声明 C# 语法,如 [SomeType (someArg1, ..., someArgN)]

c# - RedirectToAction 重定向错误与其他 namespace asp.net mvc

c# - 从动态方法解析在 IL 中找到的标记

c# - 垃圾回收失败回收BitmapImage?

c# - 为什么我无法访问另一个表单上的文本框?