Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

How to Build Xamarin.Forms NuGet

Javier Suárez edited this page May 15, 2020 · 7 revisions

Check out this updated blog post, Debugging Xamarin Open Source Frameworks: Part 1 – Xamarin.Forms

There are 2 recommended options for building Xamarin.Forms and packaging a NuGet to be distributed within a local organization.

  1. On Windows
  2. On Visual Studio Team Services (VSTS)

On Windows

The following PowerShell script will create a NuGet inside the .\artifacts\ directory. The name of the NuGet will be based on the current active branch/tag.

./build.ps1 -Target NugetPack

If you would like to use your own name then you can use the following

./build.ps1 -Target NugetPack -ScriptArgs '-packageVersion="9.9.9-custom"'

If there is no ./build.ps1 file then you are on a branch prior to the addition of the Cake scripts and you can use the following instructions

To build Xamarin.Forms Nuget locally is most easily done on a Windows machine. You'll want to use Visual Studio 2015 if you are including the soon to be deprecated Windows Phone 8 and 8.1, or you can use Visual Studio 2017.

The build is quite straight forward:

  1. Select Debug or Release
  2. Right click the solution and select Build.

A Mac build host is not required.

Once the solution is done building successfully you are ready to package the freshly made assemblies into a NuGet package. To do this, execute create-nuget.bat to generate the documentation xml for integrated IDE help and output the NuGet.

Note, this script is set to expect the debug configuration.

The NuGet package will be in your root directory when it’s complete.

On Visual Studio Team Services (VSTS)

If you don’t already have a VSTS account, sign up to get started for free. Visual Studio Team Services provides a wealth of tasks to create a very flexible build solution, and for our needs it will:

  • Get Xamarin.Forms Source
  • Restore NuGet packages
  • Build the solution
  • Generate the documentation
  • Package the NuGet
  • Publish it

First, create or choose a project on VSTS. Click New Project from your VSTS landing page and fill in your preferences. Once created, go to the Build & Release tab for the project. Create a new Build definition.

Get Xamarin.Form Source

Start with an Empty process. For the “Default agent queue” select Hosted.

The task Get Sources is provided by default. Choose that task and configure from where you want to pull your Xamarin.Forms code.

  • This project
  • Github
  • Remote repo
  • Subversion

Restore NuGet Packages

As usual, before we can build any solution including Xamarin.Forms, you want to make sure any NuGet dependencies have been restored. Visual Studio kindly does this for you by default when running a build locally.

Click Add Task and add the “NuGet” task. Change to 0.* in the Version drop down for the task. This provides the ability to customize NuGet arguments more easily. For the “Path to Solution” enter “Xamarin.Forms.sln” since it’s in the root of the repository.

Make sure the “Installation type” is set to Restore.

Include these arguments:

-source "https://www.nuget.org/api/v2;https://www.myget.org/F/nuget;https://www.myget.org/F/xamarinforms-ci/api/v3/index.json;https://www.myget.org/F/yoga/api/v3/index.json;https://www.myget.org/F/xamprojectci/api/v3/index.json;"

Build The Solution

Now we're ready to build the solution. Add another task and this time choose “Visual Studio Build”. Again, point to the “Xamarin.Forms.sln”. Add variables you can change depending on what you want to build in the Platform and Configuration fields.

Platform: $(BuildPlatform)
Configuration: $(BuildConfiguration)

When you kick off the build later, these will be options you can set.

Check the Clean box.

Package The NuGet

Finally, the step you’ve been waiting so patiently for! Add a “NuGet Packager” task and configure it.

Version 0.*
Patch to the nuspec: .nuspec/Xamarin.Forms.nuspec
Configuration to Package: $(BuildConfiguration)
Addition build properties: IdAppend=.Custom

Publish the NuGet

Perhaps you want to publish to a MyGet feed you control. You can do that here. For simplicity, let’s just put the package in a folder in the VSTS project. Add a task for Publish Build Artifacts.

Get Building

Save and queue your build. From the Builds tab you can access the build history and see your job’s status, any errors, etc.

Now you’re all set to build Xamarin.Forms and distribute within your own organization!

If you’re making fixes or customizations that everyone can benefit from, please open a pull request on GitHub and share the love.

Please do not publish to NuGet as that will create confusion with the official Xamarin.Forms package.