{"id":32564,"date":"2017-07-24T09:38:03","date_gmt":"2017-07-24T16:38:03","guid":{"rendered":"https:\/\/blog.xamarin.com\/?p=32564"},"modified":"2017-07-24T09:38:03","modified_gmt":"2017-07-24T16:38:03","slug":"building-xamarin-forms-nuget","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/building-xamarin-forms-nuget\/","title":{"rendered":"Building the Xamarin.Forms NuGet"},"content":{"rendered":"<p>\t\t\t\tA great way to explore Xamarin.Forms (and grow\u00a0comfortable working in the code) is to clone the repository and run it, especially any of the ControlGallery projects. We know that many of you have done just that, so the next step you can take is to make your own\u00a0customizations to Xamarin.Forms to build and distribute\u00a0your very own NuGet package within your organization. In this post, let\u2019s walk through doing that locally, and then discuss how you can configure the same on Visual Studio Team Services (VSTS).<\/p>\n<h2>The Local Setup<\/h2>\n<h3>Windows to Build it All<\/h3>\n<p>Building a Xamarin.Forms Nuget locally is most easily done on a Windows machine. You\u2019ll want to use Visual Studio 2015 if you&#8217;re 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:<\/p>\n<ol>\n<li>Select Debug or Release<\/li>\n<li>Right click the solution and select Build.<\/li>\n<\/ol>\n<p>I can hear you asking, \u201cBut what about a Mac build host, do I need one?\u201d because I asked the very same question my first time. Because we&#8217;re generating a NuGet and not an iOS or Mac application, we don\u2019t need the Mac build host. We&#8217;re building against the Xamarin and Windows framework SDKs.<\/p>\n<p>Once the solution is done building successfully, you should generate the xml used for displaying documentation within the IDE. Now you&#8217;re ready to package the freshly made assemblies into a NuGet package. To accomplish this, we have a handy <code>create-nuget.bat<\/code> script that you execute from the command line by name.<\/p>\n<pre class=\"EnlighterJSRAW\">if \"%DEBUG_VERSION%\"==\"\" set DEBUG_VERSION=0\nset \/a DEBUG_VERSION=%DEBUG_VERSION%+1\npushd docs\n..\\tools\\mdoc\\mdoc.exe export-msxdoc -o Xamarin.Forms.Core.xml Xamarin.Forms.Core\n..\\tools\\mdoc\\mdoc.exe export-msxdoc -o Xamarin.Forms.Xaml.xml Xamarin.Forms.Xaml\n..\\tools\\mdoc\\mdoc.exe export-msxdoc -o Xamarin.Forms.Maps.xml Xamarin.Forms.Maps\npopd\npushd .nuspec\n..\\.nuget\\NuGet.exe pack Xamarin.Forms.nuspec -properties configuration=debug;platform=anycpu -Version 9.9.%DEBUG_VERSION%\npopd<\/pre>\n<p>You can update this directly to use the version and build configuration of your choice. Note, the current script is set to expect the <code>debug<\/code> configuration. Also, notice the docs are being updated first and then the NuGet is being generated.<\/p>\n<p>The NuGet package will be in your root directory when it\u2019s complete.<\/p>\n<h3>Building on OS X<\/h3>\n<p>While you <em>can<\/em> build Xamarin.Forms on a Mac, I don\u2019t recommend it. You immediately have to trim out all the Windows targets, meaning any NuGet you create will only work on iOS, Android, and Mac. If you are on a Mac and cannot build on a Windows machine, then building on VSTS is for you!<\/p>\n<h2>Cloud Building on VSTS<\/h2>\n<p>Visual Studio Team Services provides a wealth of tasks to create a very flexible build solution, and for our needs it will:<\/p>\n<ul>\n<li>Get Xamarin.Forms Source<\/li>\n<li>Restore NuGet packages<\/li>\n<li>Build the solution<\/li>\n<li>Generate the documentation<\/li>\n<li>Package the NuGet<\/li>\n<li>Publish it<\/li>\n<\/ul>\n<p>Sounds easy enough, right?<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-32568\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/vsts-projects.png\" alt=\"\" width=\"750\" \/><\/p>\n<p>First things first, we need a project on VSTS. Click <em>New Project<\/em> from your VSTS landing page and fill in your preferences. Once that&#8217;s created, go to the Build &amp; Release tab for the project. Create a new Build definition and start adding those tasks!<\/p>\n<h3>Get Xamarin.Form Source<\/h3>\n<p>VSTS provides templates for a variety of common scenarios, but we\u2019ll start with an <em>Empty process<\/em>. For the \u201cDefault agent queue\u201d select <em>Hosted<\/em>.<\/p>\n<p>There&#8217;s one task provided for us, and that\u2019s <em>Get Sources<\/em>. Choose that task and configure from where you want to pull your Xamarin.Forms code.<\/p>\n<ul>\n<li>This project<\/li>\n<li>Github<\/li>\n<li>Remote repo<\/li>\n<li>Subversion<\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-32569\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/vsts-get-sources.gif\" alt=\"\" width=\"750\" \/><\/p>\n<h3>Restore NuGet Packages<\/h3>\n<p>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.<\/p>\n<p>Click <em>Add Task<\/em> and add the \u201cNuGet\u201d task. Change to <em>0.*<\/em> in the Version drop down for the task. This provides the ability to customize NuGet arguments more easily. For the \u201cPath to Solution\u201d enter \u201cXamarin.Forms.sln\u201d since it\u2019s in the root of the repository.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-32570\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/vsts-add-task.gif\" alt=\"\" width=\"750\" \/><\/p>\n<p>Make sure the \u201cInstallation type\u201d is set to <em>Restore<\/em>.<\/p>\n<p>Include these arguments:<\/p>\n<pre class=\"wrap:true lang:sh decode:true  \">-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;\"<\/pre>\n<h3>Build The Solution<\/h3>\n<p>Now we&#8217;re ready to build the solution. Add another task and this time choose \u201cVisual Studio Build\u201d. Again, point to the \u201cXamarin.Forms.sln\u201d. Add variables you can change depending on what you want to build in the Platform and Configuration fields.<\/p>\n<p><strong>Platform:<\/strong> $(BuildPlatform)\n<strong>Configuration:<\/strong> $(BuildConfiguration)<\/p>\n<p>When you kick off the build later, these will be options you can set.<\/p>\n<p>Check the <em>Clean<\/em> box.<\/p>\n<h3>Generate The Documentation<\/h3>\n<p>Build all the appropriate xml files needed by the IDEs to display documentation. To do this you\u2019ll need one Batch Script and three Command Line tasks. You&#8217;ve already mastered finding tasks and adding them to the process, so let\u2019s forgo repeating that. Here are the settings for those tasks.<\/p>\n<p><strong>Batch Script<\/strong>\n<strong>Display Name:<\/strong> Update XML Documentation\n<strong>Path:<\/strong> update-docs-windows.bat<\/p>\n<p><strong>Command Line<\/strong>\n<strong>Display Name:<\/strong> Generate XML Documentation (Core)\n<strong>Tool:<\/strong> $(Build.SourcesDirectory)\\tools\\mdoc\\mdoc.exe\n<strong>Arguments:<\/strong> export-msxdoc -o Xamarin.Forms.Core.xml Xamarin.Forms.Core\n<strong>Working Folder:<\/strong> docs<\/p>\n<p><strong>Command Line<\/strong>\n<strong>Display Name:<\/strong> Generate XML Documentation (XAML)\n<strong>Tool:<\/strong> $(Build.SourcesDirectory)\\tools\\mdoc\\mdoc.exe\n<strong>Arguments:<\/strong> export-msxdoc -o Xamarin.Forms.Xaml.xml Xamarin.Forms.Xaml\n<strong>Working Folder:<\/strong> docs<\/p>\n<p><strong>Command Line<\/strong>\n<strong>Display Name:<\/strong> Generate XML Documentation (XAML)\n<strong>Tool:<\/strong> $(Build.SourcesDirectory)\\tools\\mdoc\\mdoc.exe\n<strong>Arguments:<\/strong> export-msxdoc -o Xamarin.Forms.Maps.xml Xamarin.Forms.Maps\n<strong>Working Folder:<\/strong> docs<\/p>\n<h3>Package The NuGet<\/h3>\n<p>Finally, the step you\u2019ve been waiting so patiently for! Add a \u201cNuGet Packager\u201d task and configure it.<\/p>\n<p><strong>Version 0.*<\/strong>\n<strong>Patch to the nuspec:<\/strong> .nuspec\/Xamarin.Forms.nuspec\n<strong>Configuration to Package:<\/strong> $(BuildConfiguration)\n<strong>Addition build properties:<\/strong> IdAppend=.Custom<\/p>\n<h3>Publish the NuGet<\/h3>\n<p>Perhaps you want to publish to a MyGet feed you control. You can do that here. For simplicity, let\u2019s just put the package in a folder in the VSTS project. Add a task for Publish Build Artifacts.<\/p>\n<h2>Get Building<\/h2>\n<p>Save and queue your build. From the Builds tab you can access the build history and see your job\u2019s status, any errors, etc.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-32567\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/vsts-build-running.gif\" alt=\"\" width=\"750\" \/><\/p>\n<h2>Ready. Set. Build.<\/h2>\n<p>Now you\u2019re all set to build Xamarin.Forms and distribute within your own organization! If you don\u2019t already have a VSTS account, <a href=\"https:\/\/www.visualstudio.com\/\">sign up to get started for free<\/a>. Of course, if you\u2019re making fixes or customizations that everyone can benefit from, please open a pull request on GitHub and share the love.\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A great way to explore Xamarin.Forms (and grow\u00a0comfortable working in the code) is to clone the repository and run it, especially any of the ControlGallery projects. We know that many of you have done just that, so the next step you can take is to make your own\u00a0customizations to Xamarin.Forms to build and distribute\u00a0your very [&hellip;]<\/p>\n","protected":false},"author":553,"featured_media":32569,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[4,16],"class_list":["post-32564","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-xamarin-platform","tag-xamarin-forms"],"acf":[],"blog_post_summary":"<p>A great way to explore Xamarin.Forms (and grow\u00a0comfortable working in the code) is to clone the repository and run it, especially any of the ControlGallery projects. We know that many of you have done just that, so the next step you can take is to make your own\u00a0customizations to Xamarin.Forms to build and distribute\u00a0your very [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/32564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/users\/553"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=32564"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/32564\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=32564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=32564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=32564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}