NuGet package install fails “Package restore failed. Rolling back package changes for <xamarin.android>”

冷暖自知 提交于 2021-01-28 08:03:26

问题


Installing any package fails with this error, updating packages also creates this error. Clearing the NuGet cache files causes this error to change to "access to the path mono.cecil.dll is denied" when trying to install "Xamarin.GooglePlayServices.Ads". Restarting visual studio causes the package restore error to come back.

  1. Versions:

    • OS: win 10
    • Visual Studio Information:https://pastebin.com/vnuyZMWk
  2. Xamarin.Forms Project:

    • Target framework: .NET 2.0
  3. Xamarin.Android project:

    • Minimum Android Version: 5.0 (API Level 21)
    • Target Android Version: Use Compile Using SDK version (8.0)

回答1:


Well after some trial and error I have the solution.

  1. Visual Studio:

    • Update visual studio https://pastebin.com/GkEeRqg3
      • Updates Xamarin.Forms and NuGet
    • Repair visual studio from the "Visual Studio installer"
      • This Fixes the access denied to *.dll error
  2. Xamarin.Android project:

    • Set Target Android Version: 8.1 API 27
      • This makes the packages the require monoandroid81 happy.
  3. Cleaning house

    • Delete the folder C:\Users\<Your_Name>\AppData\Local\Xamarin`
      • Not sure if this was necessary but I am documenting anything I did so others can replicate the solution.
  4. Fixing NuGet

    • Right-click <Project_name>.android --> Set as startup project.
    • Tools --> NuGet Package Manager --> Package Manager Console
    • In the console CLI run Update-Package -Reinstall

Why did this happen?

One way or another some of the NuGet packages used in Xamarin.Android used monoandroid81. Even though my solution was set to use 80 some NuGet packages installed were only compatible with 81.
This was shown in the NuGet Console. Package Xamarin.Android.Support.v7.MediaRouter 27.0.2 is not compatible with monoandroid80 (MonoAndroid,Version=v8.0). Package Xamarin.Android.Support.v7.MediaRouter 27.0.2 supports: monoandroid81 (MonoAndroid,Version=v8.1)




回答2:


I faced the same error when I was trying to update the libraries one by one. Then I tried selecting all required libraries and clicked the Update button bellow the search box and it works. I have to tell that these libraries had dependencies between each other.
Here's an example:



来源:https://stackoverflow.com/questions/49495596/nuget-package-install-fails-package-restore-failed-rolling-back-package-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!