Both Xamarin.Forms and Xamarin.Essentials recently increased their Xamarin.Android.Support dependency to v28.0.0.3, and it might cause a weird error when updating NuGet Packages. Let's see how to fix it!

What's The Error?

When updating to the latest versions of Xamarin.Forms or Xamarin.Essentials, you may see one of these error messages:

Package restore failed. Rolling back package changes for 'MyApp.Android'.

or

Version conflict detected for Xamarin.Android.Support.Compat

(For nostalgia and SEO purposes, I've pasted the complete error message at the bottom of this blog post)

What Caused It?

Xamarin.Forms v4.2.0.848062 and Xamarin.Essentials v1.3.1 now target v28.0.0.3 of the Xamarin.Android.Support libraries. But, their previous versions targeted v28.0.0.1 of the Xamarin.Android.Support libraries.

Xamarin.Forms v4.2.0.778463 Xamarin.Forms v4.2.0.848062

Xamarin.Essentials v1.3.0 Xamarin.Essentials v1.3.1

Updating Xamarin.Essentials before updating Xamarin.Forms in our Xamarin.Android project is causing a NuGet Package Dependency conflict where one package needs v28.0.0.3 while the other needs v28.0.0.1.

How Do We Fix It?

The quickest way to resolve this error is to update the NuGet Package references simultaneously, directly at the source.

In the Xamarin.Android project's csproj file, we can set the NuGet Version manually:

Before

<ItemGroup> <PackageReference Include="Xamarin.Forms" Version="4.2.0.709249" /> <PackageReference Include="Xamarin.Essentials" Version="1.3.0" /> </ItemGroup>

After

<ItemGroup> <PackageReference Include="Xamarin.Forms" Version="4.2.0.848062" /> <PackageReference Include="Xamarin.Essentials" Version="1.3.1" /> </ItemGroup>

Note that I've removed every Xamarin.Android.Support library PackageReference

Conclusion

NuGet packages dependencies can sometimes be a pain, especially when two packages reference different versions of the same NuGet Package.

To fix this error in particular, we can update them both simultaneously in the Xamarin.Android csproj file.

Complete NuGet Error