Xamarin Component Store and NuGet: A Love Story

Published on April 01, 2014

I’ve published a new set of NuGet packages which allow you to depend on Xamarin Store Components in your NuGet packages. These packages, when installed, will add a Component to the target project.

NuGet Packages that have Component Dependencies

If you’re writing an Android library, your code often ends up using one of the Google Support Libraries. This goes well until you attempt to package your library into a NuGet package. What to do with the Support Library? If you include it in the package, it will blow up if the target project is already using the Support Library, and if you don’t include it, your library doesn’t work unless they include the Support Library manually.

This problem isn’t solely on Android either - the same applies for certain libraries on iOS as well, such as Xamarin.Auth or Google Maps for iOS. What do we do?

Add xamstore- references

For several Xamarin Components often used in Libraries, I’ve created “Shim packages”. Here’s how to use them:

  <?xml version="1.0"?>  
  <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">  
      <title>Helper code for Glass Apps</title>

        <dependency id="xamstore-googleglass" version="1.1" />

The package name is always the prefix xamstore-, then the Xamarin Component ID (in the URL of the store page)

Wait, so should I use this in my app?

Nope, you should just right-click on the Components folder like you did before, the only reason to use these packages is if you’re a library author. If you’re not writing a .nuspec file, you don’t need these!

What witchcraft is this??

Shim packages don’t actually contain any binaries - they simply contain a .props file which trigger Xamarin to install the listed Component into your project. Unfortunately, instead of being able to just install the component, we have to ask the user to close and reopen the solution - if anyone comes up with a clever way around this, I’d love a Pull Request!

How do I add more?

Send a pull request to paulcbetts/component-store-nupkg-builder

Anaïs Betts

Written by Anaïs [a.na'is] Betts, who lives in Berlin.

Twitter LogoCopyright 2018 Anaïs BettsGitHub Logo