简体   繁体   中英

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

I am getting the following error when trying to publish my MVC 4 project using VS2012:

Error 8 The "CollectFilesinFolder" task failed unexpectedly. 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.GetFullPathInternal(String path)
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
at System.IO.FileSystemInfo.get_FullName()

The error doesn't occur when building the solution (either debug or release) it just happens when publishing (file system).

I can't figure out which files, directory or path is causing the problem.

How or where can I see what's causing the problem?

Here is the output of my output window. I would appreciate any help to solve this issue. Thanks!

Error 8 The "CollectFilesinFolder" task failed unexpectedly. 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.GetFullPathInternal(String path)
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
at System.IO.FileSystemInfo.get_FullName()
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at 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)
at Microsoft.Web.Publishing.Tasks.CollectFilesinFolder.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext() 0 0 Nop.Web

This happens when your solution contains projects with very long names and/or has a lot of nested namespaces and/or is located in deep subfolder.

Try to move it closer to the root folder like X:\\Projects\\ or even X:. If this is not enough, you'll be forced to rename your namespaces

I faced the same problem when publishing my ASP.NET Core MVC solution in VS2015. It turned out that inside [Solution name]\\bin\\Release\\PublishOutput there was a rogue bin folder with the following contents:

[Rogue bin folder]\\bin\\Release\\PublishOutput\\bin\\Release\\PublishOutput...

I don't know for how long it went but I deleted it and the problem went away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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