Wei Loon Wong
Wei Loon Wong

Reputation: 460

Unable to update NuGet packages Xamarin.Forms to v2.5 in Xamarin.Android

I am using Windows 10 with Visual Studio Community 2017 (v15.5.6). Right now I'm trying to update NuGet packages for Xamarin.Forms from v2.3.4.231 to v2.5.

NuGet packages Xamarin.Forms updated successfully on Portable project and Xamarin.iOS project, but failed on Xamarin.Android. It keep rolling back to previous version and shows error message "The Collection is read-only".

Thanks in advance for those who can point out my mistakes. :) Many Thanks.

Upvotes: 8

Views: 2882

Answers (3)

riemannzz
riemannzz

Reputation: 2387

I had the same issue - I went to update all packages on an old Xamarin solution that hadn't been touched for several months.

I got the

"This collection is read-only"

message.

I realised I was running another instance of VS2017 for another project (and actually NuGet updating on that as well, although that may not be relevant).

I shut the other VS2017 down (and the Android emulator I'd been running, although I don't think that was relevant either).

I went through a couple of NuGet update cycles where VS2017 said something like

The package at '...\packages\Xamarin.Forms.foo.bar.w.x.y.z' failed to uninstall.

Restart Visual Studio to finish the process.

(but a different file each time)

I dutifully restarted each time and it finally came up squeaky clean with all the packages updated.

Upvotes: 0

Wei Loon Wong
Wei Loon Wong

Reputation: 460

Okay, end-up I solve this with all this steps:

(1) First select a correct Target Framework for your project. For me, I target Android Oreo. And will be good if your project is supports latest Android SDK. Go to Tools -> Android -> Android SDK Manager to check and install latest SDK.

enter image description here

(2) Before updates Xamarin.Forms 2.5, make sure certain NuGet packages in Android has up-to-date. For my case is I need to make sure packages Xamarin.Android.Support.Design has updated to version 25 or above.

enter image description here

(3) If you hit error message "The Collection is read-only". Go to Tools -> NuGet Package Manager -> Package Manager Settings and click on button Clear All NuGet Cache(s). After this, close Visual Studio -> go to your project folder -> delete all your bin and obj file -> start Visual Studio again.

enter image description here

(4) Okay, now you can update NuGet packages Xamarin.Forms to version 2.5. After update, clean and build project.

Upvotes: 2

Martin Zikmund
Martin Zikmund

Reputation: 39072

It seems it is a known issue with NuGet that happens sometimes and is caused by package cache and temporary files (see the issue report in VS Developer Community).

The solution is to go to Tools -> NuGet Package Manager -> Package Manager Settings and then click the Clear All NuGet Cache(s) button or use the Alt + C shortcut. Now close Visual Studio, navigate to your project folder and delete all obj and bin folders. Start Visual Studio again and everything should work properly now.

Upvotes: 0

Related Questions