问题
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.
Versions:
- OS: win 10
Visual Studio Information:
https://pastebin.com/vnuyZMWk
Xamarin.Forms Project:
- Target framework: .NET 2.0
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.
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
Xamarin.Android project:
- Set Target Android Version: 8.1 API 27
- This makes the packages the require monoandroid81 happy.
- Set Target Android Version: 8.1 API 27
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.
- Delete the folder C:\Users\<Your_Name>\AppData\Local\Xamarin`
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