繁体   English   中英

发布 MVC 4 应用程序时出现 PathTooLongException。 指定的路径、文件名或两者都太长

[英]PathTooLongException when publishing MVC 4 app. The specified path, file name, or both are too long

尝试使用 VS2012 发布我的 MVC 4 项目时出现以下错误:

错误 8 “CollectFilesinFolder”任务意外失败。 System.IO.PathTooLongException: 指定的路径、文件名或两者都太长。 完全限定的文件名必须少于 260 个字符,目录名必须少于 248 个字符。
在 System.IO.PathHelper.GetFullPathName()
在 System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
在 System.IO.Path.GetFullPathInternal(字符串路径)
在 System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
在 System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
在 System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess 访问,AccessControlActions 控制,String[] pathListOrig,Boolean checkForDuplicates,Boolean needFullPath,Boolean copyPathList)
在 System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
在 System.IO.FileSystemInfo.get_FullName()

该错误在构建解决方案(调试或发布)时不会发生,它只会在发布(文件系统)时发生。

我无法弄清楚是哪个文件、目录或路径导致了问题。

我如何或在哪里可以看到导致问题的原因?

这是我的输出窗口的输出。 我将不胜感激任何帮助解决此问题。 谢谢!

错误 8 “CollectFilesinFolder”任务意外失败。 System.IO.PathTooLongException: 指定的路径、文件名或两者都太长。 完全限定的文件名必须少于 260 个字符,目录名必须少于 248 个字符。
在 System.IO.PathHelper.GetFullPathName()
在 System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
在 System.IO.Path.GetFullPathInternal(字符串路径)
在 System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
在 System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
在 System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess 访问,AccessControlActions 控制,String[] pathListOrig,Boolean checkForDuplicates,Boolean needFullPath,Boolean copyPathList)
在 System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
在 System.IO.FileSystemInfo.get_FullName()
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.CollectAllFiles(String rootPath, DirectoryInfo dirinfo, Boolean recursive, List`1 result, Boolean defaultInclude, Regex[] fullPathMatchs, Regex[] relativePathMatchs, Regex[] excludeFullPathMatchs, Regex[] excludeRelativePathMatchs)
在 Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.Execute()
在 Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
在 Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() 0 0 Nop.Web

当您的解决方案包含名称很长的项目和/或具有大量嵌套命名空间和/或位于深层子文件夹中时,就会发生这种情况。

尝试将其移近根文件夹,如 X:\\Projects\\ 甚至 X:。 如果这还不够,您将被迫重命名命名空间

在 VS2015 中发布我的 ASP.NET Core MVC 解决方案时,我遇到了同样的问题。 原来在 [Solution name]\\bin\\Release\\PublishOutput 里面有一个流氓bin文件夹,里面的内容如下:

[Rogue bin 文件夹]\\bin\\Release\\PublishOutput\\bin\\Release\\PublishOutput...

我不知道它持续了多久,但我删除了它,问题就消失了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM