简体   繁体   English

“ResolveLibraryProjectImports”任务意外失败

[英]The “ResolveLibraryProjectImports” task failed unexpectedly

I have a Xamarin project, which is based on MvvmCross .我有一个基于MvvmCross的 Xamarin 项目。 The project is for both iOS and Android.该项目适用于 iOS 和 Android。 I opened this project in Visual Studio 15. I got some errors, which I solved in no time.我在 Visual Studio 15 中打开了这个项目。我遇到了一些错误,我很快就解决了。 There are some errors, which are stuck and I couldn't solve them even after searching on Google and on Stackoverflow.有一些错误被卡住了,即使在谷歌和 Stackoverflow 上搜索后我也无法解决它们。 I have tried each and every method found on Stackoverflow, but still all remaining errors are there.我已经尝试了在 Stackoverflow 上找到的每一种方法,但仍然存在所有剩余的错误。 This project is using 3rd party libraries like RestSharp and BoxApi.V2 (few more)这个项目使用了 3rd 方库,如 RestSharp 和 BoxApi.V2(更多)

I am posting my error log below.我在下面发布我的错误日志。

Severity    Code    Description Project File    Line    Suppression State
Error       The "ResolveLibraryProjectImports" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'RestSharp(Android), Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'RestSharp(Android).dll'
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(String fullName, ReaderParameters parameters)
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(String fullName)
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.GetAssembly(String fileName)
   at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(DirectoryAssemblyResolver res, ICollection`1 jars, ICollection`1 resolvedResourceDirectories, ICollection`1 resolvedAssetDirectories, ICollection`1 resolvedEnvironments)
   at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() BoxApi.V2 (Android)

This error is repeating for all projects included in this solution.此解决方案中包含的所有项目都会重复此错误。 So I am getting this error multiple times.所以我多次收到此错误。

I also want to add that the project was previously built on MAC and I am using windows, does this make some compatibility or cross OS issue?我还想补充一点,该项目以前是在 MAC 上构建的,而我使用的是 Windows,这是否会产生一些兼容性或跨操作系统问题? I have checked all assembly references and all are working fine.我已经检查了所有程序集引用,并且一切正常。

I've literally just had this with a brand new Xamarin.Forms application in Visual Studio 2017.我真的只是在 Visual Studio 2017 中使用了一个全新的 Xamarin.Forms 应用程序。

The root cause appears to be that I let VS2017 create the project in it's default location 'C:\\Users\\Dave\\Documents\\Visual Studio 2017\\Projects' and this has resulted in one of more files now having a path which it too long.根本原因似乎是我让 VS2017 在其默认位置“C:\\Users\\Dave\\Documents\\Visual Studio 2017\\Projects”中创建项目,这导致多个文件之一现在的路径太长.

I moved the solution to the root of my D drive and it builds without any problem.我将解决方案移到我的 D 驱动器的根目录,它的构建没有任何问题。

Your issue is most likely linked to this post on the Xamarin forums, and this bugzilla entry.您的问题很可能与 Xamarin 论坛上的这篇文章和bugzilla 条目相关联。 Without a reproducible sample, all I can advise you try is:如果没有可重复的样本,我只能建议您尝试:

  • Updating Xamarin for Visual Studio, Xamarin.Android, and Xamarin.iOS to the latest stable versions将 Xamarin for Visual Studio、Xamarin.Android 和 Xamarin.iOS 更新到最新的稳定版本
  • Cleaning and rebuilding清洁和重建
  • Deleting all of the bin and obj folders from your project directories从项目目录中删除所有binobj文件夹
  • Restarting Visual Studio/your PC重新启动 Visual Studio/您的 PC

Failing all of that, there's not likely to be anyone who can help you without a reproducible sample and potentially your Xamarin logs.如果所有这些都失败了,那么如果没有可重现的样本和可能的 Xamarin 日志,就不可能有任何人可以帮助您。

edit your android project file (csproj) like below像下面这样编辑你的 android 项目文件 (csproj)

在此处输入图片说明

this issue topic may guide https://github.com/xamarin/AndroidSupportComponents/issues/51这个问题主题可以指导https://github.com/xamarin/AndroidSupportComponents/issues/51

Had same problem.有同样的问题。 Here is my solution这是我的解决方案

  1. Restart Visual Studio重新启动 Visual Studio
  2. Open the Project打开项目
  3. Clean the solution清洁溶液
  4. Rebuild the solution重建解决方案
  5. Close solution关闭解决方案
  6. Reopen the project重新打开项目

I'm working with XAML ( .xaml) and code-behind file ( .xaml.cs).我正在使用 XAML ( .xaml) 和代码隐藏文件 ( .xaml.cs)。 My issue was that I had the same page name, but under different namespaces.我的问题是我有相同的页面名称,但在不同的命名空间下。 The XAML and the code behind file didn't match together. XAML 和文件背后的代码不匹配。 So finally it was an issue with my XAML, because of course it couldn't find the view element.所以最后它是我的 XAML 的一个问题,因为它当然找不到视图元素。

Well for me the problem was in my xaml file...对我来说,问题出在我的 xaml 文件中...

Somehow while setting the Layout bounds i used '.'不知何故,在设置布局边界时,我使用了 '.' as a separator instead of ','作为分隔符而不是 ','

eg例如

AbsoluteLayout.LayoutBounds="0.5.0.3,1,0.3" should have been AbsoluteLayout.LayoutBounds="0.5,0.3,1,0.3" AbsoluteLayout.LayoutBounds="0.5.0.3,1,0.3"应该是AbsoluteLayout.LayoutBounds="0.5,0.3,1,0.3"

Hence changing the '.'因此改变了'.' to ',' solved the problem to ',' 解决了问题

This happened to me when I accidentally installed nuget packages in a class library that was included in the solution.当我不小心在解决方案中包含的类库中安装了 nuget 包时,这发生在我身上。 I just had to uninstall the packages from the class library project.我只需要从类库项目中卸载包。

In my case, this issue came with another related to my xaml.就我而言,这个问题与另一个与我的 xaml 相关的问题有关。
I had to solved the second in order this error dissapear.我必须解决第二个问题才能消除此错误。 I clean up the class with a new default content and then clean all projects and solution.我使用新的默认内容清理类,然后清理所有项目和解决方案。 By last, close visual studio, open it , run the project and It works know .-.最后,关闭visual studio,打开它,运行项目,它的工作原理就知道了.-。

This is still a fresh problem, after all attempts i wanted to try to shift the code to a shorter path - however that is lot of work as svn management will get complicated, so i wanted to first verify if path is really an issue, one way to do this was to check where the android SDKs are stored.这仍然是一个新问题,在所有尝试之后,我想尝试将代码转移到更短的路径 - 但是,由于 svn 管理会变得复杂,因此需要做很多工作,所以我想首先验证路径是否真的是一个问题,一个这样做的方法是检查 android SDK 的存储位置。 I am on mac and the investigation revealed that SDKs path was longer than my project path.我在 mac 上,调查显示 SDK 路径比我的项目路径长。 Plus i tried with a fresh project, and that was compiling correctly.另外,我尝试了一个新项目,并且编译正确。

So i dropped the idea of shifting.所以我放弃了转移的想法。 Instead i used svn and compared what has changed since last correct build.相反,我使用了 svn 并比较了自上次正确构建以来发生的变化。

The comparison revealed that the project file of droid was somehow referring to the project file of iOS, it seems like some bug of Visual Studio.对比发现droid的项目文件不知何故引用了iOS的项目文件,似乎是Visual Studio的一些bug。 So i reverted the changes and than all got back to normal.所以我恢复了更改,然后一切都恢复了正常。

我遇到了同样的错误,我通常通过关闭所有其他打开的 xamarin 解决方案来解决这个问题,还有一种方法我已经解决了这个问题 -> 转到任务管理器并找到 MSBUILD 服务并结束该服务 -> 清理您的解决方案 -> 重建

We have encountered this too, it appears to be some type of race condition when building multiple projects and a very deep/complex dependency tree (our example has over 100 projects).我们也遇到过这种情况,在构建多个项目和非常深/复杂的依赖树(我们的示例有 100 多个项目)时,这似乎是某种类型的竞争条件。

The only way we've been able to resolve this (beyond continually rebuilding) is to disable Visual Studio 2017's Parallel Build Abilities (Tools->Options->Projects and Solutions->Build and Run->"1" Maximum number of parallel project builds).我们能够解决这个问题(除了不断重建)的唯一方法是禁用 Visual Studio 2017 的并行构建能力(工具->选项->项目和解决方案->构建和运行->“1”并行项目的最大数量构建)。

The problem appears to be in ResolveLibraryProjectImports.cs ( https://github.com/xamarin/xamarin-android/blob/93ddf96f86710ad848d5189858567dd7fe964579/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs ) there is most likely a race condition with their logic to shorten up the file names.问题似乎出在 ResolveLibraryProjectImports.cs ( https://github.com/xamarin/xamarin-android/blob/93ddf96f86710ad848d5189858567dd7fe964579/src/Xamarin.Android.Build.Tasks/Tasks/Resolve最有可能是raceliport)条件与他们缩短文件名的逻辑。

There are zero tests around this which means there is most likely some dodgy code.围绕此进行零测试,这意味着很可能存在一些狡猾的代码。

I am going to attempt to dig more and get an issue opened up on GitHub but finding a reliable repo is probably going to be very difficult.我将尝试挖掘更多内容并在 GitHub 上打开一个问题,但找到一个可靠的 repo 可能会非常困难。

This worked for me:这对我有用:

  • Clean solution清洁液
  • Build one project at a time starting at the top - NOT rebuild solution - just one project at a time从顶部开始一次构建一个项目 - 不要重建解决方案 - 一次只构建一个项目
  • Try deleting the contents of Obj and bin folder as well也尝试删除 Obj 和 bin 文件夹的内容
  • When done delete the project from the emulator or device before you run it again完成后,在再次运行之前从模拟器或设备中删除项目

Hope this helps.希望这可以帮助。

Still have issues ?还有问题吗? Check your namespaces and your xaml code.检查命名空间和 xaml 代码。 Sometimes when you copy/paste some files, it can be the problem.有时,当您复制/粘贴某些文件时,这可能是问题所在。

Not sure if it will help anyone of you.不确定它是否会帮助你们中的任何人。 For my case, I comment the erroneous class (eg. those with missing references), and it will start to pick up everything and build again.就我而言,我评论了错误的类(例如那些缺少引用的类),它将开始收集所有内容并重新构建。

In my case, I just forgot to delete the clicked event in XAML that doesn't exist in my code behind(cs file).就我而言,我只是忘记删除我的代码隐藏(cs 文件)中不存在的 XAML 中的 clicked 事件。 After that, I just clean and rebuild.在那之后,我只是清理和重建。

I think that error was caused by not updated references.我认为该错误是由未更新的引用引起的。

It's probably an issue with your references / reference assemblies?这可能是您的参考/参考程序集的问题?

If you look under each project's references folder in the solution explorer, any references that visual studio cannot find, delete and re-add them (right click reference folder to add).如果您在解决方案资源管理器中查看每个项目的引用文件夹下,visual studio 找不到的任何引用,删除并重新添加它们(右键单击引用文件夹以添加)。

我已经面对这个问题一千次了,当您创建一个新项目时,visual studio 在其默认文件夹中的 C:Drive 中创建它实际上是一件非常简单的事情,您所要做的就是将您的项目移出其他驱动器,例如 D:, E:不管怎样,只要确保将它保存在你的驱动器的根目录中,即如果你将它移动到 D:然后像这样放置 D/Project/solutionFile

Short Answer: 简答:

  1. Move the directory containing your solution to the Desktop 将包含解决方案的目录移动到桌面

OR 要么

  1. Delete References to the troubled library (in the References section) 删除对故障库的引用(在“参考”部分中)
  2. Close Visual Studio 关闭Visual Studio
  3. In Windows explorer Go to the Project Directory of your application (the location where your "Projectname".sln file is). 在Windows资源管理器中转到应用程序的项目目录(“Projectname”.sln文件所在的位置)。
  4. Unhide Hidden Items (View Tab; Check Hidden Items) 取消隐藏隐藏物品(查看选项卡;检查隐藏物品)
  5. Delete the "vs" hidden folder and if there is a file named "sou" delete that too. 删除“vs”隐藏文件夹,如果有名为“sou”的文件也删除。
  6. Restart Visual Studio and Launch Your Solution 重新启动Visual Studio并启动解决方案

I was facing the same solution as OP. 我正面临与OP相同的解决方案。 This is the solution to the error that the OP was having. 这是OP所遇到的错误的解决方案。 I have addressed the other cause of error which can occur for others below. 我已经解决了下面其他人可能发生的其他错误原因。

Explanation: There are usually two different types of problems that may occur. 说明:通常会出现两种不同类型的问题。 The first includes the project files being too long for System.IO.reader leading to an error including some text along the lines of "file.path too long". 第一个包括System.IO.reader的项目文件太长导致错误,包括“file.path too long”行的一些文本。

The second cause of error is due to VS forming the correct name for the dll but an incorrect path for the project resource. 导致错误的第二个原因是VS形成了dll的正确名称,但是项目资源的路径不正确。 An example could be VS using "App1\\bin\\Debug\\net452\\temp.dll" instead of "App1\\bin\\Debug\\net1.6\\temp.dll". 一个例子可能是VS使用“App1 \\ bin \\ Debug \\ net452 \\ temp.dll”而不是“App1 \\ bin \\ Debug \\ net1.6 \\ temp.dll”。

Here is the problem: System.IO.PathTooLongException: The specified path, file name, or both are too long.这是问题: System.IO.PathTooLongException:指定的路径、文件名或两者都太长。 The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.完全限定的文件名必须少于 260 个字符,目录名必须少于 248 个字符。

Try to move you project to another location like "C:/" , or change the name of the project for something more brief尝试将您的项目移动到另一个位置,例如 "C:/" ,或者更改项目名称以使其更简短

I encountered the same issue and none of the solutions above worked.我遇到了同样的问题,上面的解决方案都没有奏效。 After noticing and error on the list regarding Cryptography I knew it had to be related to FIPS being enabled (required by a VPN client)在注意到有关密码学的列表并出现错误后,我知道它必须与启用 FIPS 相关(VPN 客户端需要)

Xamarin 编译时错误

By disabling FIPS and restarting Visual Studio the issue was resolved.通过禁用 FIPS 并重新启动 Visual Studio,问题得到解决。

在此处输入图片说明

I had this error as well.我也有这个错误。 In my situation it was accompanied by Xamarin.Forms.Maps not importing into the one of the xaml.g.cs files correctly.在我的情况下,它伴随着Xamarin.Forms.Maps没有正确导入到xaml.g.cs文件之一。 I had all the using statements correct.我的所有 using 语句都是正确的。 The IDE was showing no errors but it kept telling me that Xamarin.Forms did not have a name space Map. IDE 没有显示任何错误,但它一直告诉我Xamarin.Forms没有命名空间映射。 It was generating in MapPage.xaml.g.cs as Xamarin.Forms.Map instead of Xamarin.Forms.Maps.Map and I couldn't force a fix manually.它在MapPage.xaml.g.cs成为Xamarin.Forms.Map而不是Xamarin.Forms.Maps.Map ,我无法手动强制修复。 It turned out though that the suggested xmlns:maps for maps was causing the problem.事实证明,建议的xmlns:maps地图导致了问题。 The IDE had told me to use "http://xamarin.com/schemas/2014/forms" but the correct namespace is "clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps" . IDE 告诉我使用"http://xamarin.com/schemas/2014/forms"但正确的命名空间是"clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps" After I changed this it was able to build my App1.dll在我改变这个之后它能够构建我的App1.dll

This was how I got the error.这就是我得到错误的方式。 In a StackLayout I put in a Padding property, and I seperated the 4 digits by a space rather than a comma.在 StackLayout 中,我放入了 Padding 属性,并用空格而不是逗号分隔了 4 位数字。 To find the bug I had to comment out the XAML controls individually and rebuild to isolate where the error is, and eventually I found the problem line.为了找到错误,我不得不单独注释掉 XAML 控件并重建以隔离错误所在,最终我找到了问题所在。 So basically this was the error message I got for a syntax error in my XAML code!所以基本上这就是我收到的 XAML 代码语法错误的错误消息! In any other language I would expect to be informed what the error is so I can fix it in seconds.在任何其他语言中,我希望被告知错误是什么,以便我可以在几秒钟内修复它。 But this took me a few hours - although next time I know what to do.但这花了我几个小时 - 尽管下次我知道该怎么做。

This kind of issue may also come if by mistake you have any syntactical error like in my case: two text cells were present in the ListView -如果错误地出现任何语法错误(例如在我的情况下),也可能会出现这种问题:ListView 中存在两个文本单元格 -

<ListView x:Name="ProductsView">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextCell Text="{Binding ProductId}" />
            <TextCell Text="{Binding ProductDescription}" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

I went through other posts for this issue and found the same issue occurred due to the presence of syntactical errors, which VS doesn't report directly.我浏览了有关此问题的其他帖子,发现由于存在语法错误而发生了同样的问题,VS 不会直接报告这些错误。 So look for this, otherwise, reinstall the compatible version of xamarin.forms -> clean solutions -> rebuild by reopening VS.所以寻找这个,否则,重新安装兼容版本的 xamarin.forms -> 干净的解决方案 -> 通过重新打开 VS 重建。

I have faced the same problem today.我今天遇到了同样的问题。 After two days searching, I have found the solution here .经过两天的搜索,我在这里找到了解决方案。 The issue is Xamarin.Forms library does not install all its dependent Nuget packages while first creating project by choosing cross-platform Mobile(Xamarin.Forms) project template from Visual Studio 2017. I have to manually install the upgraded dependent nuget packages to build the project successfully.问题是 Xamarin.Forms 库在首先通过从 Visual Studio 2017 选择跨平台 Mobile(Xamarin.Forms) 项目模板创建项目时没有安装其所有依赖的 Nuget 包。我必须手动安装升级的依赖 nuget 包来构建项目成功。 Also have removed and added Xamarin.Forms at the end which resolves the issue.最后还删除并添加了 Xamarin.Forms 以解决问题。

Also, it is some time creating issues when two instances of Visual Studio 2017 is running, make sure only one instance is only running as I have encountered this issue as well.此外,当两个 Visual Studio 2017 实例正在运行时会产生问题,请确保只有一个实例正在运行,因为我也遇到过这个问题。

xmlns:maps="clr-namespace:Xamarin.Forms.Maps; assembly=Xamarin.Forms.Maps"

The problem was because of the space between the semicolon above and the assembly as stated above.问题是因为上面的分号和上面提到的程序集之间有空格。 As soon as the gap is closed, it compiles.一旦间隙关闭,它就会编译。

Shorteninig the path(folder names) to the solution solved it for me.缩短解决方案的路径(文件夹名称)为我解决了这个问题。

For example : the path was : C:\\Users\\Username\\Downloads\\Compressed\\ListView-GettingStarted-in-Xamarin-Forms-master\\ListView-GettingStarted-in-Xamarin-Forms-master\\GettingStarted例如:路径是: C:\\Users\\Username\\Downloads\\Compressed\\ListView-GettingStarted-in-Xamarin-Forms-master\\ListView-GettingStarted-in-Xamarin-Forms-master\\GettingStarted

and i changed it to : C:\\Users\\HelloKali\\Downloads\\Compressed\\3\\2\\1.我将其更改为: C:\\Users\\HelloKali\\Downloads\\Compressed\\3\\2\\1.

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

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