什么可能导致“路径太长”?例外?
我正在尝试构建一个 Visual Studio 加载项。
由于冗长的原因(与使用 .NET Reflector 提供的反汇编程序集有关),我删除了对 EnvDTE 程序集的引用,然后重新添加它。我的项目仍然可以正常构建,但当我运行我的项目时,出现以下异常。
发生 System.IO.PathTooLongException 消息=指定的路径、文件名或两者都太长。完全限定文件名必须少于 260 个字符,目录名必须少于 248 个字符。 来源=mscorlib 堆栈跟踪: 在 System.IO.PathHelper.GetFullPathName() InnerException:
我的参考文献都没有特别长的路径 - 它们都是 GAC 并且长度大致相同。我不想做任何与 EnvDTE 组件遇到问题之前不同的事情。
有谁知道可能导致此问题的原因以及如何解决?
更新: 我的 csproj 文件显示以下参考路径:
<ItemGroup>
<Reference Include="BoneSoft.CSS">
<HintPath>bin\BoneSoft.CSS.dll</HintPath>
</Reference>
<Reference Include="EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Extensibility, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="HtmlAgilityPack">
<HintPath>bin\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.VisualStudio.Shell, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="microsoft.visualstudio.shell.interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.9.0, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
I'm trying to build a Visual Studio add-in.
For long-winded reasons (to do with using disassembled assemblies courtesy of .NET Reflector) I removed the reference to the EnvDTE assembly, then re-added it. My project still builds without any problems but when I run my project I get the following exception.
System.IO.PathTooLongException occurred
Message=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.
Source=mscorlib
StackTrace:
at System.IO.PathHelper.GetFullPathName()
InnerException:
None of my references have particularly long paths - they're all the GAC and roughly the same length. I'm not trying to do anything different from before I had trouble with the EnvDTE assembly.
Does anyone have any ideas what might be causing this and how it can be resolved?
UPDATE:
My csproj file shows the following reference paths:
<ItemGroup>
<Reference Include="BoneSoft.CSS">
<HintPath>bin\BoneSoft.CSS.dll</HintPath>
</Reference>
<Reference Include="EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Extensibility, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="HtmlAgilityPack">
<HintPath>bin\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.VisualStudio.Shell, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="microsoft.visualstudio.shell.interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.9.0, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在记事本中打开 .csproj 并查看所有程序集的参考条目。几乎可以肯定发生的是,它们被添加了一个奇怪的相对路径,导致它超出了 HintPath 节点中的 260 个字符限制。
要解决此问题,只需删除 HintPath 元素,重新加载项目,问题就会消失。对于 EnvDTE 来说这不是必需的。
Try opening up your .csproj in notepad and look at the Reference entries for all of your assemblies. What's almost certainly happened is they got added with a weird relative path that caused it to extend past the 260 character limit in the HintPath node.
To fix just delete the HintPath element, reload your project and the issue should go away. It isn't necessary for EnvDTE.
在我的 Silverlight 5 项目中更新对 Telerik 程序集的引用后,我也遇到了这个问题。按照 JaredPar 的建议删除 HintPath 节点后,我的问题得到了解决。我在此处提供屏幕截图以显示损坏的版本(左侧)和修复的版本(右侧)。谢谢 JaredPar...抱歉,我还不能投票支持你的答案。
I had this problem too after updating references to Telerik assemblies in my Silverlight 5 project. After deleting the HintPath nodes as JaredPar suggested, my issue was resolved. I'm providing a screen shot here to show the broken version (on left) and the fixed version (on right). Thanks JaredPar... sorry I can't vote your answer up yet.