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

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

但是当我将这个项目移动到:

C:\Users\username\Downloads\CollapsingToolbarLayout\CollapsingToolbarLayout123\App1

它在 Debug模式和 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.

另一个解决方案是使用长路径工具。作为 PIL 斯博根 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/

相关文章:

android - android timePickerDialog 的时间验证

android - EditText,清晰专注于触摸外

android - 如何创建用于创建新事件的接收器

c# - 扩展类成员的扩展方法?

performance - xamarin 表单动态添加自定义字体标签到 ScrollView 非常慢

使用 Xamarin 的 Azure 移动应用程序身份验证

android - 在 Android NDK 中编译 OpenCV

c# - 错误的 XAML 仍然编译没有错误,然后在 Xamarin.Forms 项目中发生运行时错误

.net - Visual Studio 2010 代码分析 - 在解决方案上运行

c# - 添加到 ObservableCollection - 对象引用错误