Creating Nuget Packages For Xamarin Forms

Here’s a quick post that describes how to create a nuget package that can be used across Xamarin Forms and platform specific projects. The goal is to create a nuget package that targets the appropriate platform for each project.


You need nuget.exe available from here.

Nuget Package Explorer is useful to see what has been packaged. Get it here.

All commands should be run in a command prompt with the path to the nuget.exe in the path.

Creating the Package

First we have to create a .nuspec file…

nuget spec

This creates a file called ProjectName.nuspec

Intially the file looks like this:

<?xml version="1.0"?>
<package >
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2016</copyright>
    <tags>Tag1 Tag2</tags>

The values between $ signs will be populated automatically from the projects assembly info (make sure these details are set). The remaining values can be edited or removed.

For a single assembly this is all that is required. However for a Xamarin Forms app you need to add assemblys for the platform specific project. These must be added manually. Add a files section inside the package level:

    <file src="..\Microlise.XamarinForms.Logging.Droid\Bin\Release\Microlise.XamarinForms.Logging.Droid.dll" target="lib\MonoAndroid" />
    <file src="..\Microlise.XamarinForms.Logging.IOS\Bin\Release\Microlise.XamarinForms.Logging.IOS.dll" target="lib\Xamarin.IOS" />

We are now ready to create the package…

nuget pack {projectfile}.csproj -Prop Configuration=Release

If this works a .nupkg will be created in the current folder.

Uploading The Package

You can upload your package to your nuget repository of choice. If you are using a network share to as the nuget repository you can add the new package with…

nuget init {folder with .nupkg} \\{nuget share}
Creating Nuget Packages For Xamarin Forms

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s