android - 如何修复 Xamarin Forms Android 版本中的 "ConvertResourcesCases"?

标签 android visual-studio xamarin.forms xamarin.android

我在构建 Xamarin Forms Android 模块应用程序时遇到问题。
我经常面临以下错误。

Severity Code Description Project File Line Suppression State
Error The "ConvertResourcesCases" 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.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
  at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
  at System.IO.Path.InternalGetDirectoryName(String path)
  at System.IO.Path.GetDirectoryName(String path)
  at Xamarin.Android.Tools.Files.CopyIfChanged(String source, String destination)
  at Xamarin.Android.Tasks.MonoAndroidHelper.CopyIfChanged(String source, String destination)
  at Xamarin.Android.Tasks.ConvertResourcesCases.FixupResources(ITaskItem item, Dictionary 2 acwMap)
  at Xamarin.Android.Tasks.ConvertResourcesCases.FixupResources(Dictionary 2 acwMap)
  at Xamarin.Android.Tasks.ConvertResourcesCases.Execute()
  at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
  at Microsoft.Build.BackEnd.TaskBuilder<ExecuteInstantiatedTask>d__26.MoveNext() EHG.EmployeeApp.Mobile.Android

请建议并帮助我,在此先感谢。

最佳答案

The "ConvertResourcesCases" task failed unexpectedly. System.IO.PathTooLongException: The specified path, file name, or both n are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.



这意味着 路径超出了 Windows 允许的最大值 .尝试将您的解决方案移动到磁盘的根目录,以使路径更小。例如,将其移至:
D:\YourProject

编辑:

I am facing this Issue in Release mode only, If I switch to Debug mode working fine.



我认为在 Release模式下,Windows有更严格的检查机制。为了验证这一点,我创建了一个演示,这是项目路径:
C:\Users\username\Downloads\CollapsingToolbarLayout\CollapsingToolbarLayout123\CollapsingToolbarLayout1234\CollapsingToolbarLayoutasd\CollapsingToolbarLayoutaasda\App1

它在调试模型中工作正常,但在 Release模式下面临完全相同的问题。

但是当我把这个项目移到:
C:\Users\username\Downloads\CollapsingToolbarLayout\CollapsingToolbarLayout123\App1

它在调试模型和 Release模式下都可以正常工作。所以你可以将您的项目移至更短的路径 ,我认为这是一个永久的解决方案。

Windows 有一个 最大路径长度限制 .您可以在 Windows Naming Files, Paths, and Namespaces 中看到它:

Maximum Path Length Limitation In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\some 256-character path string" where "" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.) This is the reason why you have the issue.



另一种解决方案是使用长路径工具。作为皮尔斯博根 said :

the easiest way to avoid this issue is to move your source to the C:/ drive (or another location with fewer characters in the path) or install the long path tool.

关于android - 如何修复 Xamarin Forms Android 版本中的 "ConvertResourcesCases"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46283382/

相关文章:

c# - Xamarin 表格和 map - 在 map 上获取坐标,创建路线?

xamarin.forms - 标签页 OnAppearing()

java - 计算两种颜色的组合颜色(Over 运算符)

android - Android 中生成的 values-23 文件出错

android - 如何更改 Android 上切换按钮的背景颜色

c# - 如果将摘要添加为引用,则摘要不会显示在程序集中

android - IntentService 和 Service 有什么区别?

visual-studio - 如何在针对 VS2015 的 Roslyn 分析器中使用较新的 Microsoft.CodeAnalysis 引用

c# - ASP.Net 和 Web 服务

c# - 带有 Windows 手机的 Xamarin 表单 - MediaElement 无法正常工作