<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>CI</title><link>http://www.ralbu.com:80/tags/ci</link><description>CI</description><item><title>Running Unit Tests as part of Continuous Integration of VSTS / VSO</title><link>http://www.ralbu.com:80/running-unit-tests-as-part-of-continuous-integration-of-vsts-vso</link><description>&lt;p&gt;In my &lt;a href="continuous-integration-and-deployment-of-azure-web-app-using-vsts-vso"&gt;previous blog&lt;/a&gt; I explained how to setup from scratch and deploy to Azure using VSTS. As I mentioned in the blog I left the configuration of Unit Testing for another time.&lt;/p&gt;
&lt;p&gt;In this article I will explain how you set up and run your Unit Tests as part of CI/CD process using VSTS.&lt;/p&gt;
&lt;p&gt;There are a few ways to setup Unit Tests depending on what you want to achieve. We can run the Unit Tests from a PowerShell script or we can use the &lt;em&gt;Visual Studio Test &lt;/em&gt;build step which VSTS team created for us. Let&amp;rsquo;s start with PowerShell first.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll use the same project as in the previous post &amp;ndash; &lt;em&gt;OfficeInventory.&lt;/em&gt; The Unit Test project is a standard .NET library using xUnit library. The process will be similar if you use a different Unit Test library, like NUnit.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Configuring PowerShell&lt;/h1&gt;
&lt;p&gt;When using xUnit you should make sure that the console runner is added as package so it will be restored during the build. We will use the console application to run the Unit Tests.&lt;/p&gt;
&lt;p&gt;At the root folder of the project &amp;ndash; the same level with &lt;em&gt;.sln&lt;/em&gt; I added the &lt;em&gt;Scripts &lt;/em&gt;folder. The folder will contain &lt;em&gt;run-unittests.ps1&lt;/em&gt; PowerShell script.&lt;/p&gt;
&lt;p&gt;We provide two input parameters to the script, the xunit console application path and the path we want to search for the tests projects.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;param (
    [Parameter(Mandatory=$true)][String] $xunitConsole,
    [Parameter(Mandatory=$true)][String] $sourceDirectory
)
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Next we&amp;rsquo;ll search for all the Unit Tests files we want to test excluding Java Script projects.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;$assembliesToTest = (Get-ChildItem "$sourceDirectory" -Recurse -Include "*Test*.dll" -Exclude "*JavaScript*" -Name | Select-String "bin")&lt;/pre&gt;
&lt;pre class="brush: bash;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;Now that we have all the Unit Test files we want to run let&amp;rsquo;s execute them.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;foreach ($testFile in $assembliesToTest) {

  $fileNameOnly = Split-Path $testFile -Leaf
  $unitTestFileName = Join-Path $sourceDirectory ($fileNameOnly + "-XunitTestResult.xml")

  $fullNameTestFile = Join-Path $sourceDirectory $testFile

  &amp;amp; $xunitConsole $fullNameTestFile -xml $unitTestFileName
}
&lt;/pre&gt;
&lt;p&gt;In the &lt;em&gt;$unitTestFileName&lt;/em&gt; we store the result of our Unit Test execution. We&amp;rsquo;ll use this in the &lt;em&gt;Publish Test Result&lt;/em&gt; build step.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s the full PowerShell script&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;param (
    [Parameter(Mandatory=$true)][String] $xunitConsole,
    [Parameter(Mandatory=$true)][String] $sourceDirectory
)

if (!(Test-Path $xunitConsole))
{
    throw "xunit.console.exe does not exist. Please check $xunitConsole file."
}

$assembliesToTest = (Get-ChildItem "$sourceDirectory" -Recurse -Include "*Test*.dll" -Exclude "*JavaScript*" -Name | Select-String "bin")

$atLeastOneTestRun = $false

Write-Host "[Debug] ************* Running Unit Tests *************"

foreach ($testFile in $assembliesToTest) {
    Write-Host "[Debug] *************** Testing $testFile ***************"

  $fileNameOnly = Split-Path $testFile -Leaf
  $unitTestFileName = Join-Path $sourceDirectory ($fileNameOnly + "-XunitTestResult.xml")

  $fullNameTestFile = Join-Path $sourceDirectory $testFile

  &amp;amp; $xunitConsole $fullNameTestFile -xml $unitTestFileName
  $atLeastOneTestRun = $true
}

if ($atLeastOneTestRun -eq $false) {
    Write-Output "Unit Tests didn't run!"
	exit(1)
}
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The script is ready, lets add the build steps. Edit the configuration build and in the &lt;em&gt;Add tasks&lt;/em&gt; select PowerShell Scripts.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/146dcc60e4d0_10199/powershell%20task_2.png"&gt;&lt;img title="powershell task" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="powershell task" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/146dcc60e4d0_10199/powershell%20task_thumb.png" width="754" height="768" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And after that add &lt;em&gt;Publish Test Results.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/146dcc60e4d0_10199/publish%20test%20results_2.png"&gt;&lt;img title="publish test results" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="publish test results" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/146dcc60e4d0_10199/publish%20test%20results_thumb.png" width="749" height="768" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Close the dialog and make sure both tasks are added after the B&lt;em&gt;uild &lt;/em&gt;task and before the &lt;em&gt;Publish Artifact &lt;/em&gt;task.&lt;/p&gt;
&lt;p&gt;Select the &lt;em&gt;PowerShell &lt;/em&gt;tasks and configure the following&lt;/p&gt;
&lt;p&gt;- &lt;em&gt;&lt;strong&gt;Type&lt;/strong&gt;: File Path&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;- &lt;em&gt;&lt;strong&gt;Script filename&lt;/strong&gt;: scripts/run-unittests.ps1&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;- &lt;em&gt;&lt;strong&gt;Arguments&lt;/strong&gt;: -xunitConsole "$(Build.Repository.LocalPath)\packages\xunit.runner.console.2.1.0\tools\xunit.console.exe" -sourceDirectory "$(Build.Repository.LocalPath)"&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Select the &lt;em&gt;Publish Test Results &lt;/em&gt;and configure these parameters&lt;/p&gt;
&lt;p&gt;- &lt;em&gt;&lt;strong&gt;Test Result Format&lt;/strong&gt;: XUnit&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;- &lt;/em&gt;&lt;strong&gt;Test Results Files&lt;/strong&gt;&lt;em&gt;: **/*-XunitTestResult.xml&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Now it&amp;rsquo;s time to run the build. You can see the Tests Results in the Summary page.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/146dcc60e4d0_10199/build%20success_2.png"&gt;&lt;img title="build success" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="build success" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/146dcc60e4d0_10199/build%20success_thumb.png" width="640" height="150" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Configuring the Visual Studio Test step&lt;/h1&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For this configuration we will use a &lt;em&gt;Visual Studio Test&lt;/em&gt; task. First of all, make sure that the Unit Test project has &lt;em&gt;xunit.runner.visualstudio &lt;/em&gt;package if you are using the &lt;em&gt;xUnit&lt;/em&gt; framework.&lt;/p&gt;
&lt;p&gt;Add a new build step as in the below image. That will be a &lt;em&gt;Visual Studio Test&lt;/em&gt; step&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/146dcc60e4d0_10199/VS%20Test_4.png"&gt;&lt;img title="VS Test" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" border="0" alt="VS Test" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/146dcc60e4d0_10199/VS%20Test_thumb_1.png" width="753" height="768" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You don&amp;rsquo;t have to do anything in this step, the default parameters will work ok, unless you need more features, like code coverage, running JavaScript, etc.&lt;/p&gt;
&lt;p&gt;The default configuration will include all the projects containing the name &lt;em&gt;tests &lt;/em&gt;and exclude the &lt;em&gt;obj&lt;/em&gt; folder.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;In this post I explained two ways you can run your Unit Tests during the build process using VSTS / VSO.&lt;/p&gt;
&lt;p&gt;First way is to execute a PowerShell script which will find all the tests you want to run and using a &lt;em&gt;Publish Tests Results&lt;/em&gt; to publish the tests. If you&amp;rsquo;re using &lt;em&gt;xUnit &lt;/em&gt;you need to make sure you have &lt;em&gt;xunit.runner.console&lt;/em&gt;&amp;nbsp; included as a NuGet package.&lt;/p&gt;
&lt;p&gt;The second option is easier but is not as flexible. In this case you need to have &lt;em&gt;xunit.runner.visualstudio&lt;/em&gt; NuGet package.&lt;/p&gt;</description><pubDate>Tue, 05 Jul 2016 09:00:00 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/running-unit-tests-as-part-of-continuous-integration-of-vsts-vso</guid></item><item><title>A logging library for operations or a C# feature which Java developer will appreciate</title><link>http://www.ralbu.com:80/a-logging-library-for-operations-or-a-c-feature-which-java-developer-will-appreciate</link><description>&lt;p&gt;&lt;sub&gt;&lt;/sub&gt;&lt;sub&gt;&lt;/sub&gt;This blog is not about how Java is better than C# or vice versa. It's about using existing features a language offers you - every language has its own strength.&lt;/p&gt;
&lt;p&gt;I went to &lt;a href="http://www.meetup.com/London-Continuous-Delivery" target="_blank"&gt;London Continuous Delivery&lt;/a&gt; meetup a few weeks ago where &lt;a href="https://twitter.com/seanjreilly" target="_blank"&gt;Sean Reilly&lt;/a&gt; presented a logging library with operations in mind - &lt;a href="https://github.com/EqualExperts/opslogger"&gt;opslogger&lt;/a&gt;. The library is created in Java and one of the questions was when it will be ported in .NET. In .NET we don't have to create a library for this purpose, we can extend existing libraries applying what C# language offers. If you&amp;rsquo;re a .NET developer then extension methods shouldn&amp;rsquo;t be new to you but if you&amp;rsquo;re an ops guy show this article to your devs.&lt;/p&gt;
&lt;p&gt;The main idea of the library is that it does logging for operations. I really liked it and agree with the fact that people who look after our apps are left behind in terms of what to log. Although I think the logging is for both operations and developers. The first look after the performance and the behaviour and the latter came to the scene for troubleshooting.&lt;br /&gt;The library is very opinionated, for example, you can't use different levels - there is just one level. You either log or you don't. There's no log rotation, and I agree with what Sean is saying that devops know how to configure it so you don't need a tool to do that. But, how about the applications you deploy on clients machines? In .NET world that will be Windows Forms and WPF applications. You need log rotation and you need different levels - you don't want to log everything every time on a client machine. Also, I like having different methods for logging: debug with some me&lt;sub&gt;&lt;/sub&gt;&lt;sub&gt;&lt;/sub&gt;ssage and object to be serialized as parameters and a different method to log exception with Exception instance. For example:&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;Log.Debug("Request info", request);
Log.Error("Exception when executing payment", ex);&lt;/pre&gt;
&lt;p&gt;The idea I liked in the framework is that you don't log random messages but you have a set of predefined identifications plus your log message. For example, every time the application starts you log:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;APP-001 Application started.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The code in the opslogger library looks like this:&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;logger.log(START_APP, "Application started.");&lt;/pre&gt;
&lt;p&gt;and START_APP is an enum with value "APP-0001"&lt;/p&gt;
&lt;p&gt;&amp;nbsp;If you're a .NET developer you know we can easily implement the same approach using existing logging libraries and extension methods. We have nice logging libraries with a vast amount of features. Why should we create one just for logging specific messages? What opslogger library does is that it uses a set identification messages.&lt;/p&gt;
&lt;p&gt;I used to use log4net in the past, but I switched to NLog. If you're still using log4net I definitely recommend to have a look at NLog. In this example I will use NLog.&lt;/p&gt;
&lt;p&gt;I have created a sample ASP.NET MVC application to prove the idea. You can find it on &lt;a href="https://github.com/ralbu/nlog-extension"&gt;github&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We're going to extend NLog with a set of predefined methods with specific messages. For example:&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt; public static class LoggerExtension
    {
        public static void ActionInit(this ILogger logger, string message)
        {
            logger.Debug($"APP-001 {message}");
        }
        public static void Performance(this ILogger logger, string message)
        {
            logger.Debug($"PERFORMANCE-001 {message}");
        }
    }
&lt;/pre&gt;
&lt;p&gt;And we'll use it like that:&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;Logger.ActionInit("HomeController Index");&lt;/pre&gt;
&lt;p&gt;Have a look at log output below. You can see that it's easy to search for particular messages. Let's say you want to filter all the performance logs, in this case you use &lt;em&gt;PERFORMANCE-001&lt;/em&gt; tag and depending what system you use to store logging you can have a nice filter/view of the data.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:04:26.1665|DEBUG|NLogExtension.Controllers.HomeController|APP-001 HomeController Index&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:04:26.1860|DEBUG|NLogExtension.Controllers.HomeController|Get all users&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:04:26.8906|DEBUG|NLogExtension.Controllers.HomeController|&lt;strong&gt;PERFORMANCE-001 Getting users in: 700&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:04:26.8946|DEBUG|NLogExtension.Controllers.HomeController|Searching for active items&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:04:27.1998|DEBUG|NLogExtension.Controllers.HomeController|&lt;strong&gt;PERFORMANCE-001 Searching active items in: 301&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:04:27.2478|DEBUG|NLogExtension.Controllers.HomeController|Sample debug message&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:10:06.0037|DEBUG|NLogExtension.Controllers.HomeController|APP-001 HomeController Index&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:10:06.0322|DEBUG|NLogExtension.Controllers.HomeController|Get all users&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:10:06.7354|DEBUG|NLogExtension.Controllers.HomeController|&lt;strong&gt;PERFORMANCE-001 Getting users in: 700&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:10:06.7464|DEBUG|NLogExtension.Controllers.HomeController|Searching for active items&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:10:07.0559|DEBUG|NLogExtension.Controllers.HomeController|&lt;strong&gt;PERFORMANCE-001 Searching active items in: 300&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:10:07.0559|DEBUG|NLogExtension.Controllers.HomeController|Sample debug message&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:10:07.5652|DEBUG|NLogExtension.Controllers.HomeController|APP-001 HomeController About&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;2016-03-10 14:10:08.8938|DEBUG|NLogExtension.Controllers.HomeController|APP-001 HomeController Contact&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As you can see we can achieve the same output as opslogger with any logger library we want in a very flexible way.&lt;/p&gt;</description><pubDate>Wed, 16 Mar 2016 10:25:33 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/a-logging-library-for-operations-or-a-c-feature-which-java-developer-will-appreciate</guid></item><item><title>Continuous Integration and Deployment of Azure Web App using VSTS / VSO</title><link>http://www.ralbu.com:80/continuous-integration-and-deployment-of-azure-web-app-using-vsts-vso</link><description>&lt;p&gt;A new addition to the Microsoft&amp;rsquo;s Visual Studio Team Services (former VSO) continuous integration and deployment is the Release tool. The CI/CD process I&amp;rsquo;m describing here applies to VSTS but at some point it will be released to TFS as well. Microsoft invested its effort into building a nice continuous integration and deployment pipeline. The new online VSTS build and release tools are much better than the old XAML builds. I have been working with &lt;a href="https://www.jetbrains.com/teamcity/" target="_blank"&gt;TeamCity&lt;/a&gt; for a very good number of years and I was surprised with Microsoft&amp;rsquo;s new addition. I started working with Build and Release tools very earlier for one of our clients -&amp;nbsp; since private previews. It was called Visual Studio Online at that time. My experience is that they are moving very fast. I ported a few of our TeamCity builds and deployment configurations over to VSTS and it was easier than I expected. Taking into the account that I almost had zero documentation I progressed very quickly.&lt;/p&gt;
&lt;p&gt;In this article I will explain how you can build and deploy a Web site into Azure Web App. VSTS contains a template for Azure Web Sites which makes our life easier. It contains Cloud Services and IIS Web Applications also. And if there&amp;rsquo;s anything you need which is missing you can always use PowerShell.&lt;/p&gt;
&lt;p&gt;The solution we&amp;rsquo;re going to deploy represents an ASP.NET MVC Application but a WebForms application will have the same approach. For the sake of simplicity I created an ASP.NET MVC Application and named it &lt;strong&gt;OfficeInventory&lt;/strong&gt;.&lt;/p&gt;
&lt;h1&gt;Create a build configuration&lt;/h1&gt;
&lt;p&gt;Open Build tab in VSTS and click the plus button:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/add-build_2.png"&gt;&lt;img title="add-build" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="add-build" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/add-build_thumb.png" height="364" border="0" width="392" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Select an Empty template in the popup windows and click Next. There is a &lt;strong&gt;Visual Studio&lt;/strong&gt; Template but it will add build steps which we don&amp;rsquo;t need, like Visual Studio Test and Index Sources.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/select-empty-template_2.png"&gt;&lt;img title="select-empty-template" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="select-empty-template" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/select-empty-template_thumb.png" height="484" border="0" width="483" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the next step select the source settings. Default agent in this case will be Hosted, unless you&amp;rsquo;ve installed your own agent. With the hosted agent you have 240 free minutes per month. Check Continuous Integration check box and click Create.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/configure-source-control_2.png"&gt;&lt;img title="configure-source-control" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="configure-source-control" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/configure-source-control_thumb.png" height="484" border="0" width="486" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First we&amp;rsquo;ll configure the build and after that we&amp;rsquo;ll add build steps.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Repository configuration&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;ll come back and update the build and publish build steps but for the moment open the &lt;strong&gt;Repository&lt;/strong&gt; tab. You should have already source settings in place. The settings I&amp;rsquo;m explaining below refer to a Git repository. If you want the build process to download all the source code every time it builds select true for the&amp;nbsp; &lt;strong&gt;Clean&lt;/strong&gt; dropdown. Depending how big your project is this may slow down the build process. If you want to tag your source code then select the appropriate value in the &lt;strong&gt;Label sources&lt;/strong&gt;. Adding tags to you build will make sense when you create NuGet packages but it will provide less information for normal builds. By default &lt;strong&gt;Label format&lt;/strong&gt; contains the build number. I will explain later how to set it.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Variables configuration&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;Variables &lt;/strong&gt;tab contains our variables definition we can use during the build process. We can use them in the following format:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;$(VariableName)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s add the following variables:&lt;/p&gt;
&lt;table border="0" cellpadding="2" cellspacing="0" width="400"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;BuildConfiguration&lt;/td&gt;
&lt;td valign="top" width="200"&gt;Release&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;BuildPlatform&lt;/td&gt;
&lt;td valign="top" width="200"&gt;Any CPU&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Triggers configuration&lt;/h2&gt;
&lt;p&gt;In the &lt;strong&gt;Triggers &lt;/strong&gt;tab we can configure when to run the build. You can set it up to run as &lt;strong&gt;Continuous integration&lt;/strong&gt; and include filters based on branch names. When you check &lt;strong&gt;Batch changes&lt;/strong&gt; option it will include several check-ins if they are from the same committer. You can run the build on a schedule as well. Adding the schedule will help when you want to run builds which takes more time, like testing.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;General&lt;/h2&gt;
&lt;p&gt;In the &lt;strong&gt;General &lt;/strong&gt;tab you can change the Agent Queue, build authorisation, badge displayed on external web site etc. We&amp;rsquo;re interested in setting the &lt;strong&gt;Build Number&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;I like setting the build number following the classic approach: &lt;em&gt;major.minor.build.revision&lt;/em&gt;. In this case, if I want the build number to be &lt;em&gt;1.0.3.[RevisionNo]&lt;/em&gt; then I use the format &lt;em&gt;1.0.3.$(Rev:r)&lt;/em&gt;. If you prefer to use a different system to name your builds, like using date, then find more information online at this &lt;a href="https://msdn.microsoft.com/en-us/library/hh190719%28v=vs.120%29.aspx" target="_blank"&gt;MSDN link&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Retention&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;Retention &lt;/strong&gt;tab allows to specify for how many days you can keep the build details, including test results. The default value is 30 days and at the moment you can&amp;rsquo;t change that.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Build steps&lt;/h2&gt;
&lt;p&gt;We have created an empty build, now lets add the configuration we need. Click &lt;strong&gt;Add build step&amp;hellip;&lt;/strong&gt; in the list of &lt;strong&gt;Tasks&lt;/strong&gt; select &lt;strong&gt;Build &lt;/strong&gt;on the left hand side and search for Visual Studio Build. Click the &lt;strong&gt;Add&lt;/strong&gt; button. Next select &lt;strong&gt;Utility&lt;/strong&gt; on the left hand side and click the &lt;strong&gt;Add &lt;/strong&gt;button of the &lt;strong&gt;Publish Build Artifacts&lt;/strong&gt;. Now you can close the popup.&lt;/p&gt;
&lt;h3&gt;Build solution&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s go back to the &lt;strong&gt;Build &lt;/strong&gt;tab and select &lt;strong&gt;Visual Studio Build.&lt;/strong&gt; We need to provide settings on the right hand side. First of all, you may want to add a meaningful name to this step, so click on the pencil in the right hand side, above all the settings and enter the name you want.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Solution&lt;/strong&gt; text box contains **\*.sln &amp;ndash; you can leave it like that or click on the ellipsis button and select the solution file from the tree.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;MSBuild Arguments &amp;ndash; &lt;/strong&gt;we need to create a package which we&amp;rsquo;ll deploy later in Azure Web App. In order to do this we&amp;rsquo;ll use the command line&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=$(Build.StagingDirectory)\OfficeInventory&lt;/pre&gt;
&lt;p&gt;Pay attention to the &lt;strong&gt;PackageLocation&lt;/strong&gt; parameter. This is where our package will be copied. We&amp;rsquo;ll use this path in the next step to publish the package. We use &lt;em&gt;Build.Staging&lt;/em&gt; variable which is a predefined build variable. The package will be copied to staging directory of our build and in the &lt;em&gt;OfficeInventory &lt;/em&gt;folder. The staging folder is generated by the build agent.&amp;nbsp; Find more information about build and release variables at &lt;a title="Use variables" href="https://msdn.microsoft.com/en-us/Library/vs/alm/Build/scripts/variables" target="_blank"&gt;Use variables&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For the &lt;strong&gt;Platform &lt;/strong&gt;and &lt;strong&gt;Configuration &lt;/strong&gt;provide the variables we&amp;rsquo;ve created before: &lt;em&gt;$(BuildPlatform)&lt;/em&gt; and &lt;em&gt;$(BuildConfiguration)&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Check the &lt;strong&gt;Clean &lt;/strong&gt;checkbox if you want to start the build with all the files removed from previous builds.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/build-vs-settings_2.png"&gt;&lt;img title="build-vs-settings" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="build-vs-settings" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/build-vs-settings_thumb.png" height="351" border="0" width="804" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Publish package&lt;/h3&gt;
&lt;p&gt;The next step is to publish the package so we can use it during the Release process. Select the &lt;strong&gt;Publish Build Artifacts &lt;/strong&gt;step. In the &lt;strong&gt;Path to Publish &lt;/strong&gt;enter &lt;em&gt;$(Build.StagingDirectory)\OfficeInventory. &lt;/em&gt;For the &lt;strong&gt;Artifact Name &lt;/strong&gt;provide a name you want. In my case it&amp;rsquo;s &lt;strong&gt;OfficeInventory&lt;/strong&gt;. In the &lt;strong&gt;Artifact Type &lt;/strong&gt;select &lt;strong&gt;Server&lt;/strong&gt; unless you want to copy the package to a shared folder.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/build-publish-settings_2.png"&gt;&lt;img title="build-publish-settings" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="build-publish-settings" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/build-publish-settings_thumb.png" height="307" border="0" width="814" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now it&amp;rsquo;s time to save if you haven&amp;rsquo;t yet and run the build.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Release&lt;/h1&gt;
&lt;p&gt;Open the Release tab. As I&amp;rsquo;m writing this blog the Release is in public preview.&lt;/p&gt;
&lt;p&gt;Click on the &lt;strong&gt;Plus &lt;/strong&gt;button and select &lt;strong&gt;Azure Website Deployment&lt;/strong&gt;. It will add a new environment with &lt;strong&gt;Azure Deployment &lt;/strong&gt;and &lt;strong&gt;Visual Studio Test&lt;/strong&gt; tasks for that environment.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/release-website_2.png"&gt;&lt;img title="release-website" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="release-website" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/release-website_thumb.png" height="484" border="0" width="381" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Delete the &lt;strong&gt;Visual Studio Test &lt;/strong&gt;because we&amp;rsquo;re not going to configure it &amp;ndash; I will post another article about configuring Unit Testing.&lt;/p&gt;
&lt;p&gt;You can rename the environment if you want to. Usually you&amp;rsquo;ll create a few environments, like Dev, Testing, Staging, etc.&lt;/p&gt;
&lt;p&gt;Click on the &lt;strong&gt;Artifacts&lt;/strong&gt; tab then click on the &lt;strong&gt;Link an artifact source.&lt;/strong&gt; Select the build you want to link to. There is nothing to add on the &lt;strong&gt;Configuration &lt;/strong&gt;tab so click on the &lt;strong&gt;Triggers &lt;/strong&gt;tab. Check the &lt;strong&gt;Continuous deployment &lt;/strong&gt;and select the artifact and the environment. In the &lt;strong&gt;General &lt;/strong&gt;tab I will change the default name format to &lt;em&gt;Office Inventory - 1.0.0.$(rev:r)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/release-artifact_2.png"&gt;&lt;img title="release-artifact" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="release-artifact" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/release-artifact_thumb.png" height="353" border="0" width="644" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In order to deploy to Azure you need to configure the Azure subscription first. Click on the &lt;strong&gt;Manage&lt;/strong&gt; link on &lt;strong&gt;Azure Subscription&lt;/strong&gt; of the &lt;strong&gt;Azure Web App Deployment &lt;/strong&gt;task. This will open a new page. On that page click on the &lt;strong&gt;New Service Endpoint&lt;/strong&gt; and Select &lt;strong&gt;Azure&lt;/strong&gt; from the list. This will open a modal windows where you need to enter Azure details. The easiest way to get that information is hovering you mouse on the exclamation icon and click on the &lt;strong&gt;publish settings file &lt;/strong&gt;link. That will download the Azure publish settings file. That file is an XML file so open it in your favourite editor. I prefer to use &lt;strong&gt;Certificate Based&lt;/strong&gt; instead the &lt;strong&gt;Credentials&lt;/strong&gt; type because I don&amp;rsquo;t want people to enter their credentials. In any case, extract the information you need from the &lt;strong&gt;publish settings&lt;/strong&gt; file, like &lt;strong&gt;Subscription Id, Name&lt;/strong&gt;, etc. and click OK.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/release-add-azure-connection_2.png"&gt;&lt;img title="release-add-azure-connection" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="release-add-azure-connection" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/release-add-azure-connection_thumb.png" height="377" border="0" width="644" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s go back to the &lt;strong&gt;Environments&lt;/strong&gt; page and click on the Refresh button on the right hand side of the &lt;strong&gt;Azure Subscription.&lt;/strong&gt; Enter the name of your &lt;strong&gt;Azure Web App&lt;/strong&gt;, select the location and the slot (Production or Staging). Click on the Ellipses button select the package.&lt;/p&gt;
&lt;p&gt;Now we&amp;rsquo;re ready to deploy. Save the release and click on the &lt;strong&gt;Release&lt;/strong&gt; button and next &lt;strong&gt;Create Release.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/release-webapp_5.png"&gt;&lt;img title="release-webapp" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="release-webapp" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/release-webapp_thumb_1.png" height="281" border="0" width="804" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;NOTE: You can rename the Tasks if you click the pencil on the right hand side of the task Title.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/release-rename-task_2.png"&gt;&lt;img title="release-rename-task" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="release-rename-task" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/8f26ee4939c1_6DEB/release-rename-task_thumb.png" height="66" border="0" width="244" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now you can add multiple environments and continuously deploy to them.&lt;/p&gt;</description><pubDate>Thu, 25 Feb 2016 14:02:31 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/continuous-integration-and-deployment-of-azure-web-app-using-vsts-vso</guid></item><item><title>Visual Studio Online - output colouring by tag</title><link>http://www.ralbu.com:80/visual-studio-online-output-colouring-by-tag</link><description>&lt;p&gt;I started being more involved in continuous integration and deployment using Visual Studio Online which is &amp;lsquo;the new&amp;lsquo; TFS hosted in Azure.&lt;/p&gt;
&lt;p&gt;I've discovered an interesting and useful feature when using it PowerShell. When you use Write-Host if you add [Debug], [Warning] and [Error] in your output string then you get a nice colour in the Console and Logs pages of the build result.&lt;/p&gt;
&lt;p&gt;Have a look at the below images.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/bb1a0ef004f8_5FF5/vso%20build%201_4.png"&gt;&lt;img title="vso build 1" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="vso build 1" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/bb1a0ef004f8_5FF5/vso%20build%201_thumb_1.png" height="118" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/bb1a0ef004f8_5FF5/vso%20build%202_4.png"&gt;&lt;img title="vso build 2" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="vso build 2" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/bb1a0ef004f8_5FF5/vso%20build%202_thumb_1.png" height="150" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In this example the following output was used:&lt;/p&gt;
&lt;p&gt;Write-Host "[Debug] Debug value"&lt;br /&gt;Write-Host "[Warning] Warning value"&lt;br /&gt;Write-Host "[Error] Error value"&lt;/p&gt;
&lt;p&gt;As you can see the Console doesn't shows the value in square brackets.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;This worked for me in both Azure hosted and local hosted agent. I guess it should be the same on the TFS hosted on premises.&lt;/p&gt;</description><pubDate>Wed, 23 Sep 2015 06:09:32 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/visual-studio-online-output-colouring-by-tag</guid></item><item><title>Azure Mobile Service deployment with Team City part 7. Deployment to Test environment</title><link>http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-7-deployment-to-test-environment</link><description>&lt;p&gt;The last step in these series of posts is deploying from TeamCity to a test environment.&lt;/p&gt;
&lt;p&gt;We have already created the script which will do the deployment so we need only to create the TeamCity configuration.&lt;/p&gt;
&lt;p&gt;Although we can call the script which will do the deployment directly from TeamCity I prefer to have another separate script which at its turn will call the deployment script. In this way we test it locally and if we need to add more functionality we don't have to change the TeamCity configuration. For this purpose we create &lt;em&gt;run-delpoy.ps1&lt;/em&gt; script which will have the same set of parameters as &lt;em&gt;deploy-package.ps1&lt;/em&gt;. The script takes input parameters and calls the &lt;em&gt;deploy-package.ps1&lt;/em&gt; script.&lt;/p&gt;
&lt;p&gt;Make sure you have created a test Azure Mobile Service instance.&lt;/p&gt;
&lt;p&gt;Now let&amp;rsquo;s configure TeamCity. On the User Management settings page (Administration &amp;gt; User Management) and click Create build configuration.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/989ffbd253ae_F5EC/p71_2.png"&gt;&lt;img title="p71" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="p71" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/989ffbd253ae_F5EC/p71_thumb.png" height="332" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I will name it Mobile Service Test Deploy and click Create button.&lt;/p&gt;
&lt;p&gt;In the next step &amp;ndash; Version Control Settings select User Management and click Attach.&lt;/p&gt;
&lt;p&gt;Click on the Build Steps if it didn&amp;rsquo;t open automatically and click Add build step. Select Powershell from the Runner type drop-down. Give a name to the step and select Powershell mode and error output. Working directory will be &lt;em&gt;MobileService/Scripts&lt;/em&gt; and Script file will be &lt;em&gt;MobileService/Scripts/run-deploy.ps1&lt;/em&gt;. The last part is adding the Script arguments.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;packageLocation&lt;/em&gt; parameter indicates where the package is located &amp;ndash; it is defined by this value:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;"%teamcity.build.checkoutDir%\Package"&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This represent the Package folder in the checkout directory. The content of the Package folder will be generated by the Artfact dependency as you&amp;rsquo;ll see later.&lt;/p&gt;
&lt;p&gt;The rest of the parameters value we extract from the Mobile Service publish profile as described in &lt;a target="_blank" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-4-deploying-azure-mobile-services"&gt;this post&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/989ffbd253ae_F5EC/p72_2.png"&gt;&lt;img title="p72" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="p72" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/989ffbd253ae_F5EC/p72_thumb.png" height="620" border="0" width="1024" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We need to link this build configuration to Mobile Service Team City build configuration we created in previous steps. Open the Dependencies and click on the &lt;em&gt;Add new artifact dependency&lt;/em&gt; button. In the Depend on select the Mobile Service, select &lt;em&gt;Last successful build &lt;/em&gt;from Get artifacts from and in Artifacts rules enter:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Package=&amp;gt;./Package&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/989ffbd253ae_F5EC/p73_2.png"&gt;&lt;img title="p73" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="p73" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/989ffbd253ae_F5EC/p73_thumb.png" height="476" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;re almost done, one last step &amp;ndash; we need to know which package was deployed to Test environment. Open the &lt;em&gt;General Settings&lt;/em&gt; and in the &lt;em&gt;Build number format &lt;/em&gt;enter:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Mobile Service-%dep.UserManagement_MobileService.build.number%&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This will tell us which Mobiles service package version was deployed to Test environment.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/989ffbd253ae_F5EC/p74_2.png"&gt;&lt;img title="p74" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="p74" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/989ffbd253ae_F5EC/p74_thumb.png" height="463" border="0" width="1024" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now we&amp;rsquo;re ready to run our deployment. On the Project page click on the ellipses Run button of the Deploy project and then click on the Dependencies tab. Select which build you want to deploy and click Run Build&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/989ffbd253ae_F5EC/p75_2.png"&gt;&lt;img title="p75" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="p75" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/989ffbd253ae_F5EC/p75_thumb.png" height="252" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The build run and the package was deployed successfully. As you can see the Test Deploy build indicates which Build package it used to deploy: #Mobile Service-0.0.2.37&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/989ffbd253ae_F5EC/p76_2.png"&gt;&lt;img title="p76" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="p76" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/989ffbd253ae_F5EC/p76_thumb.png" height="197" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;With this blog post I&amp;rsquo;ve finished all the posts about building and deploying an Azure Mobile Service. I&amp;rsquo;ve started from &lt;a target="_blank" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-1-team-city-installation"&gt;installing and configuring TeamCity&lt;/a&gt;, creating &lt;a target="_blank" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-3-build-azure-mobile-service-with-powershell-using-psake"&gt;PowerShell scripts to build and deploy&lt;/a&gt; up to configuring TeamCity to deploy on Test environment.&amp;nbsp; Although it is concentrated on the Azure Mobile Service you might find some bits of it useful in other type of projects.&lt;/p&gt;
&lt;p&gt;I hope you&amp;rsquo;ll find it useful.&lt;/p&gt;</description><pubDate>Fri, 04 Sep 2015 06:05:21 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-7-deployment-to-test-environment</guid></item><item><title>Azure Mobile Service deployment with Team City part 6. Integrate SpecFlow with TeamCity</title><link>http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-6-integrate-specflow-with-teamcity</link><description>&lt;p&gt;In the previous &lt;a target="_blank" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-5-configuring-mobile-in-teamcity"&gt;blog post&lt;/a&gt; I explained how to configure TeamCity to run a PowerShell script which will deploy an Azure Mobile Service.&lt;/p&gt;
&lt;p&gt;After the Mobile Service was deployed we want to run acceptance tests. I&amp;rsquo;ve created a sample C# project using SpecFlow. It doesn&amp;rsquo;t have to be Acceptance Tests, I just wanted to give an example of how you&amp;rsquo;ll integrate SpecFlow with TeamCity. The solution contains the &amp;ldquo;Specifications&amp;rdquo; project which are a set of SpecFlow scenarios. SpecFlow has the ability to generate reports &amp;ndash; we&amp;rsquo;ll be generating one report and integrate it with TeamCity.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll create a new file &amp;ndash; &lt;em&gt;acceptance-tests.ps1&lt;/em&gt; in the Scripts folder.&lt;/p&gt;
&lt;p&gt;In order to generate a report we need to run a command which executes the NUnit tests as described in the documentation &lt;a href="https://github.com/techtalk/SpecFlow/wiki/Reporting"&gt;https://github.com/techtalk/SpecFlow/wiki/Reporting&lt;/a&gt;. For this purpose we need NUnit console app. I&amp;rsquo;ve added nuget package manually. Otherwise, it will install the package as a solution package.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;&amp;lt;package id="NUnit.Runners" version="2.6.4" /&amp;gt;&lt;/pre&gt;
&lt;p&gt;First step is to execute the acceptance tests with the &lt;em&gt;nunit-console runner&lt;/em&gt;.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;&amp;amp; $nunitRunner /nologo /labels /out=TestResult.txt /xml=TestResult.xml /framework:net-4.0 $acceptanceTests&lt;/pre&gt;
&lt;p&gt;It will generate two files: &lt;em&gt;TestResult.txt&lt;/em&gt; and &lt;em&gt;TestResult.xml&lt;/em&gt;. These files will be used when invoking SpecFlow report generation. TestResult name is the default name so if you don&amp;rsquo;t change it then in the next step you don&amp;rsquo;t have to provide additional parameters. You just need to provide the SpecFlow project file.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;&amp;amp; $specFlow nunitexecutionreport "..\Source\Specifications\Specifications.csproj" /out:"..\TestResult.html"&lt;/pre&gt;
&lt;p&gt;This will generate &lt;em&gt;TestResult.html&lt;/em&gt; report file in the root folder.&lt;/p&gt;
&lt;p&gt;Another moment here I need to highlight &amp;ndash; the &lt;em&gt;specflow.exe&lt;/em&gt; is compiled for .NET 3.5 so it cannot load .NET 4.0 assemblies. You can find more details at &lt;a href="https://github.com/techtalk/SpecFlow/wiki/Reporting#step-definition-report" target="_blank"&gt;Step Definition Report&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For this reason we copy &lt;em&gt;specflow.exe.config &lt;/em&gt;file to the packages folder.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;Copy-Item -path "specflow.exe.config" -destination $specFlowFolder&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;h2&gt;Configure SpecFlow reporting in TeamCity&lt;/h2&gt;
&lt;p&gt;We can update our build so that after deployment it runs the SpecFlow Acceptance Tests and gives us the detailed report about the execution.&lt;/p&gt;
&lt;p&gt;In the TeamCity configuration page open the Build Steps page. Add a new build step. As you might guess this will be another PowerShell configuration. The configuration is similar to the one &lt;a target="_blank" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-5-configuring-mobile-in-teamcity"&gt;we did before&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Working directory is &lt;em&gt;MobileService/Scripts&lt;/em&gt; and Script file is &lt;em&gt;MobileService/Scripts/acceptance-tests.ps1&lt;/em&gt; with no parameters.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p61_2.png"&gt;&lt;img title="p61" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p61" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p61_thumb.png" height="480" border="0" width="592" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Next we need to configure TeamCity to display our SpecFlow report. First we add &lt;em&gt;Build Feature &amp;ndash; XML Report processing&lt;/em&gt;. The purpose of this is that TeamCity will take our &lt;em&gt;TestsResult.xml&lt;/em&gt; file will parse it and report the results as the build results. In this way we can add out Acceptance Tests to be part of the CI process and they will be displayed in Test Results tab as well.&lt;/p&gt;
&lt;p&gt;In the &lt;em&gt;Build Configuration Settings &lt;/em&gt;page click on the &lt;em&gt;Build Features &lt;/em&gt;and &lt;em&gt;Add build feature&lt;/em&gt;. Select &lt;em&gt;XML report processing &lt;/em&gt;from the drop down and select NUnit&lt;em&gt; &lt;/em&gt;from the Report type. Add &lt;em&gt;Scripts\TestResult.xml &lt;/em&gt;in the Monitoring rules.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p62_2.png"&gt;&lt;img title="p62" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p62" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p62_thumb.png" height="423" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Next step we&amp;rsquo;ll configure TeamCity result page to display the SpecFlow result page &lt;em&gt;TestResult.html &lt;/em&gt;in a new tab.&lt;/p&gt;
&lt;p&gt;Open the Administration page and click on the User Management project.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p63_2.png"&gt;&lt;img title="p63" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p63" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p63_thumb.png" height="221" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Click on the Report Tabs link.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p64_4.png"&gt;&lt;img title="p64" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="p64" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p64_thumb_1.png" height="342" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Click on the Create new build report tab. In the new dialog enter the Tab title &amp;ndash; that will be the title of the tab which appears in the build result page and Start page which in our case will be TestResult.html.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p65_2.png"&gt;&lt;img title="p65" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="p65" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p65_thumb.png" height="292" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The Start page represents an artifact page which means that the TestResult.html page should be an artifact entity created by TeamCity. In order to do this go to the Build Configuration Settings and open the General Settings page. We have added already our package which gets deployed as an artifact. Now we need to add in the Artifact paths:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;MobileService\TestResult.html=&amp;gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p66_2.png"&gt;&lt;img title="p66" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="p66" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p66_thumb.png" height="539" border="0" width="1024" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now when we run the build we have a nice SpecFlow report.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p67_2.png"&gt;&lt;img title="p67" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="p67" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/f92ddafeb994_E893/p67_thumb.png" height="469" border="0" width="1024" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This finishes the full continuous integration and deployment of an Azure Mobile Service in TeamCitiy.&lt;/p&gt;
&lt;p&gt;But there one last step which is outside of this deployment pipeline &amp;ndash; in the next post we&amp;rsquo;ll configure TeamCity to deploy a package to Test environment which was deployed and tested on Dev environment.&lt;/p&gt;
&lt;p&gt;&lt;a target="_self" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-5-configuring-mobile-in-teamcity"&gt;&amp;lt; Previous&lt;/a&gt;&lt;/p&gt;</description><pubDate>Fri, 28 Aug 2015 05:02:32 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-6-integrate-specflow-with-teamcity</guid></item><item><title>Azure Mobile Service deployment with Team City part 5. Configuring Mobile in TeamCity</title><link>http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-5-configuring-mobile-in-teamcity</link><description>&lt;p&gt;In the previous &lt;a target="_blank" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-4-deploying-azure-mobile-services"&gt;post&lt;/a&gt; we finished to create all the PowerShell scripts. The build and deployment run locally. Now it&amp;rsquo;s time to create a TeamCity configuration for it.&lt;/p&gt;
&lt;p&gt;Open the TeamCity web page and click on the arrow on the right hand side of User Management Project page and then Edit Settings from the menu.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_B356/p51_2.png"&gt;&lt;img title="p51" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p51" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_B356/p51_thumb.png" height="386" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Click on the Create build configuration.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_B356/p52_2.png"&gt;&lt;img title="p52" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p52" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_B356/p52_thumb.png" height="258" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Give it a name &amp;ndash; I use Mobile Service and click Create.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_B356/p53_2.png"&gt;&lt;img title="p53" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p53" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_B356/p53_thumb.png" height="281" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It opens the Version Control Settings page where I will attach the VCS root previously created.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_B356/p56_2.png"&gt;&lt;img title="p56" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p56" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_B356/p56_thumb.png" height="222" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Next step is to create the build configuration. Click on the Build Steps and Add build step.&lt;/p&gt;
&lt;p&gt;Select PowerShell Runner Type, specify the step name and select the PowerShell mode.&lt;/p&gt;
&lt;p&gt;Click the Show advanced options link at the bottom of the page if you don&amp;rsquo;t see all the settings.&lt;/p&gt;
&lt;p&gt;Select error value in Error Output drop down.&lt;/p&gt;
&lt;p&gt;Enter &lt;em&gt;MobileService/Scripts&lt;/em&gt; in Working directory&lt;/p&gt;
&lt;p&gt;Enter the script file &lt;em&gt;MobileService/Scripts/run-build.ps1&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Make sure &lt;em&gt;Execute .ps1 from external file&lt;/em&gt; is selected in Script execution mode.&lt;/p&gt;
&lt;p&gt;Click Expand on the Script arguments and enter:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;-version %build.number% &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;-contentPath "contentPath" &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;-computerName "computerName" &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;-userName "userName"&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;-password "password"&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Replace all the necessary values as described in &lt;a target="_blank" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-4-deploying-azure-mobile-services"&gt;Azure Mobile Service deployment with Team City part 4. Deploying Azure Mobile Services&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_B356/p57_2.png"&gt;&lt;img title="p57" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p57" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_B356/p57_thumb.png" height="600" border="0" width="1024" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Click Save.&lt;/p&gt;
&lt;p&gt;We need to configure a few more settings.&lt;/p&gt;
&lt;p&gt;Click on the &lt;em&gt;General Settings&lt;/em&gt; and enter the Build number format. I use Major.Minor.Build.Revision pattern: 0.0.2.%build.counter%.&lt;/p&gt;
&lt;p&gt;In the Artifact paths enter&lt;/p&gt;
&lt;p&gt;&lt;i&gt;MobileService\Artifacts=&amp;gt;Package&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;In our script at the build step we copy the package which we need to deploy in the Artifacts folder. Now we tell TeamCity to use that folder to create a build Artifact. You&amp;rsquo;ll see later how we use it do deploy to other environments.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_B356/p58_2.png"&gt;&lt;img title="p58" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p58" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_B356/p58_thumb.png" height="603" border="0" width="1024" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Open the Failure Conditions from the left hand site and select &amp;ldquo;an error message is logged by build runner&amp;rdquo;. In some cases when the PowerShell returns an error, like failed to deploy the mobile service TeamCity will mark the build as green &amp;ndash; success. When you select this option it will fail the build.&lt;/p&gt;
&lt;p&gt;Now when you run this build it will execute all the PowerShell steps and will deploy the Azure Mobile Service.&lt;/p&gt;
&lt;p&gt;In the next post we&amp;rsquo;ll configure SpecFlow to integrate with TeamCity.&lt;/p&gt;
&lt;p&gt;&lt;a target="_self" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-4-deploying-azure-mobile-services"&gt;&amp;lt; Previous&lt;/a&gt;&lt;/p&gt;</description><pubDate>Thu, 06 Aug 2015 09:08:03 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-5-configuring-mobile-in-teamcity</guid></item><item><title>Azure Mobile Service deployment with Team City part 3. Build Azure Mobile Service with PowerShell using psake</title><link>http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-3-build-azure-mobile-service-with-powershell-using-psake</link><description>&lt;p&gt;TeamCity is a very powerful tool and you can take advantage of all its configuration options to create your CI and CD. Although TeamCity provides you with almost everything you need, like restoring packages, update version, build, running unit tests, etc. I&amp;rsquo;m going to write all these steps in a PowerShell script. It is easier to use what TeamCity offers from the start but when the complexity of building and deploying increases it will be difficult to maintain.&lt;/p&gt;
&lt;p&gt;Having the deployment process as a set of scripts will give you some advantages, like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Run and test the deployment process on your machine&lt;/li&gt;
&lt;li&gt;Evolve the deployment system incrementally&lt;/li&gt;
&lt;li&gt;Ability to test every step in isolation&lt;/li&gt;
&lt;li&gt;Checking changes in source control and ability to revert to previous versions if needed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The scripts will be written in PowerShell and I will use &lt;a href="https://github.com/psake/psake" target="_blank"&gt;psake&lt;/a&gt; which is a PowerShell tool to provide task-oriented dependencies.&lt;/p&gt;
&lt;p&gt;Initially we&amp;rsquo;ll start with three scripts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;local.ps1 &amp;ndash; we&amp;rsquo;ll use this script to run the entire set of script on local machine; it contains default parameters and it executes run-build.ps1&lt;/li&gt;
&lt;li&gt;run-build.ps1 &amp;ndash; the script is called by TeamCity providing all the necessary parameters. It invokes the build.ps1 script using psake module&lt;/li&gt;
&lt;li&gt;builid.ps1 &amp;ndash; contains all the steps necessary to build the project&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Tools&lt;/h2&gt;
&lt;p&gt;First we need to get psake scripts from the &lt;a href="https://github.com/psake/psake/releases" target="_blank"&gt;git releases page&lt;/a&gt; and copy them to the Tools folder. We need the nuget.exe as well. Download it from &lt;a href="https://nuget.org/nuget.exe" target="_blank"&gt;Command-Line Utility URL&lt;/a&gt; . Copy nuget.exe in the Tools folder.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Local script&lt;/h2&gt;
&lt;p&gt;All the scripts are located in the Scripts folder.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;local.ps1&lt;/em&gt; script clears the screen and executes the &lt;em&gt;run-build.ps1&lt;/em&gt; script. It contains a few default parameters. One of the parameter is &lt;em&gt;debugConfiguration&lt;/em&gt;. We use that for debugging purposes. For example when we work on the deployment task we might not want to run all the tasks which are time consuming, like restore packages so we&amp;rsquo;ll ignore it.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Run-build script&lt;/h2&gt;
&lt;p&gt;The &lt;em&gt;run-build.ps1&lt;/em&gt; script imports psake module and executes &lt;em&gt;build.ps1&lt;/em&gt; script in the context of the psake module. It invokes the script with parameters which don&amp;rsquo;t have default values and properties which have default values.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Build script&lt;/h2&gt;
&lt;p&gt;All the steps before running the build and the build itself are done in this &lt;em&gt;build.ps1&lt;/em&gt; script.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll start with changing how psake prints out the tasks it runs. This will make a better separation between tasks and will be easier to read.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;FormatTaskName "$([Environment]::NewLine)==================== $(Get-Date -format T) - Executing {0} ===================="&lt;/pre&gt;
&lt;p&gt;We&amp;rsquo;ll use the precondition parameter to conditionally run a task. For example, if we don&amp;rsquo;t want to restore packages we&amp;rsquo;ll use the &lt;em&gt;$debugConfiguration.restorePackage&lt;/em&gt; parameter.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;Task RestoreNuGetPackages -Depends Clean -Precondition {return $debugConfiguration -eq $null -or $debugConfiguration.restorePackage } {&lt;/pre&gt;
&lt;p&gt;The task will run when precondition returns true. I check for null value of the &lt;em&gt;debugConfiguration &lt;/em&gt;variable because it will be&amp;nbsp; null when running from TeamCity so we don&amp;rsquo;t want to skip the step.&lt;/p&gt;
&lt;p&gt;Bear in mind that if the task execution depends on another task then that task will not run if precondition of the task in execution returns false.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll start with adding the default task.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;Task Default -Depends DeployPackage&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Clean&lt;/h3&gt;
&lt;p&gt;First of all we need to clean everything. For that we&amp;rsquo;ll build the solution with Clean target and also delete the packages folder.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;Task Clean -Precondition { return $debugConfiguration -eq $null -or $debugConfiguration.clean } {
 Exec {
        msbuild $solutionToBuild /t:Clean /verbosity:$verbosity /nologo /p:Configuration=$config /p:VisualStudioVersion=12.0
    }

  if (Test-Path "..\Source\packages") {
     Remove-Item "..\Source\packages" -Recurse -Force -ErrorAction Stop
  }
  else {
    "Didn't find the 'packages' folder."
  }
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Restore packages&lt;/h3&gt;
&lt;p&gt;Every single build needs to restore all the packages, in this way we make sure that packages are not missing on the build machine.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;Task RestoreNuGetPackages -Depends Clean -Precondition { return $debugConfiguration -eq $null -or $debugConfiguration.restorePackage } {
    if (!(Test-Path $nugetExe)){
        throw "nuget.exe could not be found on this machine. Please check: $nugetExe"
    }
    Exec {
      &amp;amp; $nugetExe restore $solutionToBuild
    }
}&lt;/pre&gt;
&lt;p&gt;Our mobile service project references a NuGet package hosted on the TeamCity machine. But the NuGet feed requires authentication. In order to restore that package on the TeamCity machine during the build process we need to allow the restore process to authenticate to that NuGet feed. There is a command line we need to run on the TeamCity VM.&lt;/p&gt;
&lt;p&gt;Login on the TeamCity server and make sure that you use the same account you used when you installed the TeamCity agent. It&amp;rsquo;s important that the agent runs under the same account. We configured the agent in &lt;a href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-1-team-city-installation" target="_blank"&gt;step 1&lt;/a&gt; where I mentioned that. NuGet should add the configuration file (NuGet.config) in the same user&amp;rsquo;s folder.&lt;/p&gt;
&lt;p&gt;For example, if you run the agent under the &amp;lsquo;teamcity&amp;rsquo; user name then when you add the NuGet source as below (run the below command) it will create or update the file in this location:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;C:\Users\teamcity\AppData\Roaming\NuGet\NuGet.Config&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This is the command line you need to run:&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;NuGet.exe Sources Add &amp;ndash;Name [GIVE_A_NAME] -Source [TEAMCITY_FEED] &amp;ndash;UserName [USER_NAME] &amp;ndash;Password [PASSWORD]&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;Sources&lt;/em&gt; &amp;ndash; TeamCity NuGet feed. Check the &lt;a href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-2-configure-teamcity-nuget-server" target="_blank"&gt;configure NuGet server post&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;UserName &lt;/em&gt;&amp;ndash; user name you provided when you setup TeamCity. You can create a new user name just for this purpose but in this case you&amp;rsquo;ll need to run the agent under this user&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Password &lt;/em&gt;&amp;ndash; user name&amp;rsquo;s password&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Update assembly version&lt;/h3&gt;
&lt;p&gt;There are different methods to update the assembly version. You can keep the version in one AssemblyInfo.cs file and add that file as a link to all the projects but I don&amp;rsquo;t like this idea because you can forget to do that and some of your libraries will not have the version updated. Instead of that I iterate through all the projects and update the version for every single &lt;em&gt;AssemblyInfo.cs&lt;/em&gt; file.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;Task UpdateVersion -Precondition { return $debugConfiguration -eq $null -or $debugConfiguration.updateVersion } {
    (Get-ChildItem -Path $sourceDirectory -Filter AssemblyInfo.cs -Recurse) |
    ForEach-Object {
      (Get-Content $_.FullName) |
        ForEach-Object {
          $_ -replace 'AssemblyVersion.+$',"AssemblyVersion(`"$version`")]" `
          -replace 'AssemblyFileVersion.+$',"AssemblyFileVersion(`"$version`")]"
        } |
        Out-File $_.FullName
    }
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Build&lt;/h3&gt;
&lt;p&gt;The build process should create a package which will be deployed to Azure. In order to do this we&amp;rsquo;ll use &lt;em&gt;DeployOnBuild=true&lt;/em&gt; and &lt;em&gt;PublishProfile=PublishProfile.xml &lt;/em&gt;parameters.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;PublishProfile.pubxml&lt;/em&gt; file doesn&amp;rsquo;t exist. We need to generate it. In order to do this we have the &lt;em&gt;pubxml.template&lt;/em&gt; file in the Scripts folder. It contains the following xml:&lt;/p&gt;
&lt;pre class="brush: xml;"&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&amp;gt;
  &amp;lt;PropertyGroup&amp;gt;
    &amp;lt;WebPublishMethod&amp;gt;FileSystem&amp;lt;/WebPublishMethod&amp;gt;
    &amp;lt;LastUsedBuildConfiguration&amp;gt;Release&amp;lt;/LastUsedBuildConfiguration&amp;gt;
    &amp;lt;LastUsedPlatform&amp;gt;Any CPU&amp;lt;/LastUsedPlatform&amp;gt;
    &amp;lt;SiteUrlToLaunchAfterPublish /&amp;gt;
    &amp;lt;LaunchSiteAfterPublish&amp;gt;False&amp;lt;/LaunchSiteAfterPublish&amp;gt;
    &amp;lt;ExcludeApp_Data&amp;gt;True&amp;lt;/ExcludeApp_Data&amp;gt;
    &amp;lt;publishUrl&amp;gt;{0}&amp;lt;/publishUrl&amp;gt;
    &amp;lt;DeleteExistingFiles&amp;gt;True&amp;lt;/DeleteExistingFiles&amp;gt;
  &amp;lt;/PropertyGroup&amp;gt;
&amp;lt;/Project&amp;gt;
&lt;/pre&gt;
&lt;p&gt;You can change it if you need to. We&amp;rsquo;re interested in the &lt;em&gt;publishUrl &lt;/em&gt;value &amp;ndash; we need to populate it during the build process with the package location. If you&amp;rsquo;re going to have a fixed package location then you can hard-code it but in our case the location will be driven by the TeamCity. We&amp;rsquo;ll generate the package in the &lt;em&gt;&amp;ldquo;[Root]\Artifacts&amp;rdquo;&lt;/em&gt; folder. Root is the folder where our Scripts and Source folders are located.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;PublishProfile.pubxml&lt;/em&gt; file is generated in the method &amp;ldquo;GetPublishProfile&amp;rdquo; and will be saved in &amp;ldquo;&lt;em&gt;[Root]\Artifacts&lt;/em&gt;&amp;rdquo; folder. Later it is overwritten by the build with the package. To some extend this simulates the same process you have when you deploy from Visual Studio.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;function GetPublishProfile() {
    # Get the publish xml template and generate the .pubxml file
    $scriptPath = Split-Path -parent $PSCommandPath

    if (Test-Path $artifactDirectory) {
        Remove-Item $artifactDirectory -Recurse -Force -ErrorAction Stop
    }

    [String]$template = Get-Content $scriptPath\pubxml.template

    mkdir $artifactDirectory | Out-Null
    $xml = $template -f $artifactDirectory
    $outputPublishProfile = Join-Path $artifactDirectory "PublishProfile.pubxml"
    $xml | Out-File -Encoding utf8 -FilePath $outputPublishProfile

    return $outputPublishProfile
}&lt;/pre&gt;
&lt;pre class="brush: bash;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre class="brush: bash;"&gt;Task Build -Depends RestoreNuGetPackages, UpdateVersion {
    $publishProfile = GetPublishProfile 

    Exec {
        msbuild $projectToBuild /p:DeployOnBuild=true /p:PublishProfile=$publishProfile /verbosity:$verbosity /nologo /p:Configuration=$config /p:VisualStudioVersion=12.0
    }
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Unit Tests&lt;/h3&gt;
&lt;p&gt;All the Unit Tests were implemented using &lt;a href="https://github.com/xunit/xunit" target="_blank"&gt;xunit&lt;/a&gt;. First we need to build the solution which will create the Test*.dll files. After that we&amp;rsquo;ll run every Test*.dll file by &lt;em&gt;xunit.exe&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;xunit.exe&lt;/em&gt; file is added as a NuGet package. In order to do that we need to add this to our Test project, otherwise it will create a .nuget folder with packages.config file and we&amp;rsquo;ll put it under the solution folder. You can add it as I NuGet package for the solution but I don't really like it for small projects.&lt;/p&gt;
&lt;pre class="brush: xml;"&gt;  &amp;lt;package id="xunit.runner.console" version="2.0.0" /&amp;gt;&lt;/pre&gt;
&lt;p&gt;The full source code of the Unit Test&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;Task Test -Depends Build {
  if (!(Test-Path $xunitConsole))
  {
    throw "xunit.console.exe does not exist. Please check $xunitConsole file."
  }

   "************* Build solution [$solutionToBuild] for Unit Testing *************"
  # Need to run the solution to build all the tests. The Build Task run only the csproj file
  exec {
    msbuild $solutionToBuild /verbosity:m /p:Configuration=$config /p:VisualStudioVersion=12.0 /nologo
  }

  $assembliesToTest = (Get-ChildItem "$sourceDirectory" -Recurse -Include "*Test*.dll" -Name | Select-String "bin")

  $atLeastOneTestRun = $false

  "************* Running Unit Tests *************"
  foreach ($testFile in $assembliesToTest){
    "*************** Testing $testFile ***************"
    $fullNameTestFile = Join-Path $sourceDirectory $testFile
    
    &amp;amp; $xunitConsole $fullNameTestFile
    $atLeastOneTestRun = $true
  }

  if ($atLeastOneTestRun -eq $false){
    Write-Output "Unit Tests didn't run!"
    exit(1)
  }
}
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now we can build and test our project. In the next post I will explain how to deploy an Azure Mobile Service.&lt;/p&gt;
&lt;p&gt;&lt;a target="_self" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-2-configure-teamcity-nuget-server"&gt;&amp;lt; Previous post&lt;/a&gt;&lt;/p&gt;</description><pubDate>Thu, 16 Jul 2015 05:02:40 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-3-build-azure-mobile-service-with-powershell-using-psake</guid></item><item><title>Create NuGet packages using AppVeyor</title><link>http://www.ralbu.com:80/create-nuget-packages-using-appveyor</link><description>&lt;p&gt;This blog explains how to create a NuGet package and use AppVeyor as a continuous integration and deployment tool.&lt;/p&gt;
&lt;p&gt;I found out about &lt;a href="http://www.appveyor.com/"&gt;AppVeyor&lt;/a&gt; some time ago from Scott's blog - "&lt;a href="http://www.hanselman.com/blog/AppVeyorAGoodContinuousIntegrationSystemIsAJoyToBehold.aspx"&gt;AppVeyor - A good continuous integration system is a joy to behold&lt;/a&gt;". Usually I use TeamCity running on a VM so I didn't have a chance to try it out until recently when I built a &lt;a href="https://www.nuget.org/packages/RandomUser"&gt;NuGet package&lt;/a&gt; to generate random users. The NuGet package is based on the &lt;a href="https://randomuser.me"&gt;https://randomuser.me&lt;/a&gt; API &amp;ndash; a free API to generate random user data. You would use it in prototyping, testing or filling your database with proper user names, pictures, etc.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.appveyor.com/"&gt;AppVeyor&lt;/a&gt; is a cloud based continuous integration and delivery service for .NET. It is free for open source projects. It has everything you need and it is really easy to set up. It has a nice Web UI where you configure your build and deployment settings but in this post I will explain the minimum configuration you need to publish a NuGet package using the appveyor.yml file. The reason I prefer to keep my configurations in a file rather than using the UI is that I can version it and when I break something I can fix it fast just by checking the differences in the file.&lt;/p&gt;
&lt;p&gt;Every AppVeyor configuration can contain an appveyor.yml file in the root folder. If you have the file and also configure the UI then the YAML file will override the UI settings unless you explicitly disable it in &lt;i&gt;Ignore appveyor.yml &lt;/i&gt;settings in the UI.&lt;/p&gt;
&lt;p&gt;AppVeyor also has the option to host NuGet packages. Before pushing the NuGet package to &lt;a href="https://www.nuget.org"&gt;https://www.nuget.org&lt;/a&gt; I use that to test my packages.&lt;/p&gt;
&lt;p&gt;Here's the full YAML file. As you can see, it is self-descriptive and I will explain only the settings which are not clear from the first glance or might be confusing.&lt;/p&gt;
&lt;pre class="brush: text;"&gt;version: 0.9.{build}

assembly_info:
  patch: true
  file: AssemblyInfo.cs
  assembly_version: '{version}'
  assembly_file_version: '{version}'
  assembly_informational_version: '{version}'

platform: Any CPU

configuration: Release

build:
  project: RandomUser.sln
  verbosity: detailed
  publish_nuget: true

before_build:
  - nuget restore

nuget:
  account_feed: true
  project_feed: true

deploy:
  provider: NuGet
  api_key:
    secure: oersntns349lpwtsaAThuwfs//74hanwoIEN
  skip_symbols: false
  artifact: /.*\.nupkg/&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Will let AppVeyor to take care of the release version number. For this purpose &lt;em&gt;{build}&lt;/em&gt; is used. Assembly files will be patched with the version value we define in &amp;ldquo;version&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;In order to publish to NuGet the following should be added to the appveyor.yml file&lt;/p&gt;
&lt;pre class="brush: text;"&gt;build:
  publish_nuget: true

deploy:
  provider: NuGet
  api_key:
    secure: oersntns349lpwtsaAThuwfs//74hanwoIEN
  skip_symbols: false
  artifact: /.*\.nupkg/&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You need to get your NuGet API key and encrypt it. AppVeyor offers a tool for encryption at this URL &lt;a href="https://ci.appveyor.com/tools/encrypt"&gt;https://ci.appveyor.com/tools/encrypt&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In &lt;i&gt;artifact&lt;/i&gt; you provide the file name or artifact name to push.&lt;/p&gt;
&lt;p&gt;As I said before I prefer to create NuGet packages using AppVeyor feed before pushing them for the first time to nuget.org. For this purpose you need to add the following:&lt;/p&gt;
&lt;pre class="brush: text;"&gt;nuget:
  account_feed: true
  project_feed: true&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Make sure that your project contains a &lt;i&gt;nuspec &lt;/i&gt;file in the same folder where your .csproj file is. You can find more information about &lt;i&gt;nuspec&lt;/i&gt; here: &lt;a href="http://docs.nuget.org/Create/Nuspec-Reference"&gt;http://docs.nuget.org/Create/Nuspec-Reference&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;All the tests are run automatically by the way.&lt;/p&gt;</description><pubDate>Fri, 22 May 2015 07:45:39 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/create-nuget-packages-using-appveyor</guid></item><item><title>Displaying AppVeyor build status badge in a repository</title><link>http://www.ralbu.com:80/displaying-appveyor-build-status-badge-in-a-repository</link><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you're using &lt;a href="https://ci.appveyor.com"&gt;AppVeyor&lt;/a&gt; for your CI then you can display the build status in your repository readme page. You do that by using the Status Badge. There&amp;rsquo;s is good documentation on their web site &lt;a href="http://www.appveyor.com/docs/status-badges"&gt;http://www.appveyor.com/docs/status-badges&lt;/a&gt;. But if you're doing this for the first time then you might get confused as to which option to choose and where to get the data you need.&lt;/p&gt;
&lt;p&gt;If you don't want to read an entire blog about badges then head to your AppVeyor project page, click on the &lt;em&gt;&lt;strong&gt;settings&lt;/strong&gt;&lt;/em&gt; link and then click on the &lt;strong&gt;&lt;em&gt;Badges&lt;/em&gt;&lt;/strong&gt; link. Search for &lt;em&gt;Sample markdown code, &lt;/em&gt;copy that code and put it in your repository page. You're done.&lt;/p&gt;
&lt;p&gt;If you're still reading then you want to know more details, so choose the option that suits you better. The examples I will provide are from my &lt;a href="https://github.com/ralbu/randomuser"&gt;randomuser&lt;/a&gt; GitHub repository.&lt;/p&gt;
&lt;h1&gt;Public repositories from GitHub or Bitbucket&lt;/h1&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If your source code repository is public then you have two options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use the URL as described above from your project settings&lt;/li&gt;
&lt;li&gt;Use the URL from your public repository. In this case you need to have only one AppVeyor project.&lt;br /&gt;The URL has the following format:&lt;br /&gt;&lt;code&gt;https://ci.appveyor.com/api/projects/status/{github|bitbucket}/{repository}&lt;/code&gt; For example:&lt;br /&gt;&lt;code&gt;https://ci.appveyor.com/api/projects/status/github/ralbu/randomuser&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I would prefer the second choice for public repositories. In the first case you need to embed your AppVeyor project id into the url. I'm not sure about the security implications in this case, if let's say you want to make the AppVeyor project private. In this case you don't want to expose that id.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Status Badge options&lt;/h1&gt;
&lt;p&gt;You have three options when displaying a badge:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A simple badge. Use the URL with no query string parameters &lt;br /&gt;&lt;code&gt;https://ci.appveyor.com/api/projects/status/github/ralbu/randomuser&lt;/code&gt; &lt;br /&gt;&lt;img alt="" src="/Media/Default/Windows-Live-Writer/Displaying-AppVeyor-build-status-badge-o_99C0/av13_2.png" height="18" width="100" /&gt; &lt;br /&gt;Retina badge. Add &lt;em&gt;retina=true&lt;/em&gt; parameter &lt;br /&gt;&lt;code&gt;https://ci.appveyor.com/api/projects/status/github/ralbu/randomuser?retina=true&lt;/code&gt; &lt;br /&gt;&lt;img alt="" src="/Media/Default/Windows-Live-Writer/Displaying-AppVeyor-build-status-badge-o_99C0/av%20retina_2.png" height="36" width="200" /&gt; &lt;br /&gt;This parameter will scale the image but the image doesn't look very sharp.&lt;/li&gt;
&lt;li&gt;SVG badge. Add &lt;em&gt;svg=true&lt;/em&gt; parameter &lt;br /&gt;&lt;code&gt;https://ci.appveyor.com/api/projects/status/github/ralbu/randomuser?svg=true&lt;/code&gt;&amp;nbsp;&lt;br /&gt;&lt;a href="http://localhost:400/Media/Default/Windows-Live-Writer/Displaying-AppVeyor-build-status-badge-o_99C0/apsvg.png"&gt;&lt;/a&gt;&lt;img alt="" src="/Media/Default/Windows-Live-Writer/Displaying-AppVeyor-build-status-badge-o_99C0/apsvg.png" height="36" width="176" /&gt; &lt;br /&gt;I like this badge and I use it instead of the first two.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&amp;nbsp;&lt;/h1&gt;
&lt;h1&gt;Building state of the status badge&lt;/h1&gt;
&lt;p&gt;There is a difference in the status displayed on the badge when the project is queued or in building process on the SVG image compared with other two images.&lt;br /&gt;The SVG badge says 'pending' and the other two say 'building...'&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Display the status badge in the Markdown format&lt;/h1&gt;
&lt;p&gt;&lt;br /&gt;When using the Markdown format you &lt;span style="background-color: #ffff00;"&gt;&lt;/span&gt;display the badge status using the following format &lt;br /&gt;&lt;code&gt;[![Alt img description](Badge Url as described above)](The url to your AppVeyor status page.)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[![Build status](https://ci.appveyor.com/api/projects/status/github/ralbu/randomuser?svg=true)](https://ci.appveyor.com/api/projects/status/github/ralbu/&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;&lt;br /&gt;You have other options to choose from, like displaying the status of a branch. More information can be found on &lt;a href="http://www.appveyor.com/docs/status-badgesing"&gt;http://www.appveyor.com/docs/status-badgesing&lt;/a&gt;&lt;/p&gt;</description><pubDate>Wed, 29 Apr 2015 21:21:00 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/displaying-appveyor-build-status-badge-in-a-repository</guid></item><item><title>Hosting NuGet in TeamCity and consume it in Visual Studio</title><link>http://www.ralbu.com:80/post/2013/07/15/Hosting-NuGet-in-TeamCity-and-consume-it-in-Visual-Studio</link><description>&lt;h2&gt;&amp;nbsp;&lt;/h2&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;This post describes the setup of NuGet package inside TeamCity and configuration of your Visual Studio to consume the hosted packages. TeamCity version 7.1 is used.&lt;/p&gt;
&lt;p&gt;When you work on a big or medium projects you&amp;rsquo;ll end up having at least one common library. If you keep everything in one solution then you don&amp;rsquo;t have problems with sharing the common library &amp;ndash; you reference the common project to all other projects which need it.&lt;/p&gt;
&lt;p&gt;How about the case when you have multiple separate solutions/projects and want to use the common library. In this cases you have two options: a) add the common library into all the projects as &lt;em&gt;Add Existing Project&lt;/em&gt; and b) add a reference to the common dll file. With both approaches you have tackle a set of issues, like how to update the common library and not to break the projects using it; what if you need to use it for a project in a location different to the library, let&amp;rsquo;s say common library is located on c:/project but the project using it is located on D:/WebSites. These are just a few issues but enough to give you a headache.&lt;/p&gt;
&lt;p&gt;All these issues will go away by implementing your common libraries as NuGet packages. You can host these packages on the NuGet web site but you might not want to do it. Here I explain how to host them in TeamCity.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Pre NuGet Build Configuration setup&lt;/h2&gt;
&lt;p&gt;Will start with standard build configuration steps. In TeamCity create a new Build Configuration. Set the &lt;em&gt;Build number format&lt;/em&gt; as it will help to keep track on the versioning and make the update process easier. Set &lt;em&gt;Version Control settings&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Add a &lt;em&gt;Build Step&lt;/em&gt; which will build your package solution. If needed add &lt;span style="font-family: 'Courier New';"&gt;/p:Configuration=Release&lt;/span&gt; to &lt;em&gt;Command line parameters&lt;/em&gt; to build the release.&lt;/p&gt;
&lt;p&gt;Add a unit test build step if it is the case. For example select the &lt;em&gt;MSTest&lt;/em&gt; as &lt;em&gt;Runner type&lt;/em&gt; if you do MS Unit testing. Add the following &lt;span style="font-family: 'Courier New';"&gt;**\bin\**\*.Tests.dll&lt;/span&gt; in the &lt;em&gt;List assembly files.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;NuGet package configuration&lt;/h2&gt;
&lt;p&gt;Next is the part which is most interested for us. But before that make sure you have the NuGet set in &lt;em&gt;Administration &amp;gt; NuGet Settings&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Add a new &lt;em&gt;Build Step &lt;/em&gt;and in the &lt;em&gt;Runner type&lt;/em&gt; select &lt;em&gt;NuGetPack&lt;/em&gt;. If you set the NuGet settings you should have NuGet.exe dropdown with the NuGet version.&lt;/p&gt;
&lt;p&gt;In the &lt;em&gt;Specification files&lt;/em&gt; select the project you want to create a package from.&lt;/p&gt;
&lt;p&gt;Update &lt;em&gt;Version&lt;/em&gt; to &lt;span style="font-family: 'Courier New';"&gt;%build.number%&lt;/span&gt; if you want to keep the same version you set in &lt;em&gt;General Settings&lt;/em&gt; of your build configuration.&lt;/p&gt;
&lt;p&gt;Set the &lt;em&gt;Output Directory. &lt;/em&gt;For instance, &lt;span style="font-family: 'Courier New';"&gt;Build\packages&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Make sure you check the &lt;em&gt;Publish created packages to build artifacts.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Also you might want to check &lt;em&gt;Include sources and symbols&lt;/em&gt; but not mandatory.&lt;/p&gt;
&lt;p&gt;NOTE:&lt;/p&gt;
&lt;p&gt;In the &lt;em&gt;Build Steps &lt;/em&gt;screen add &lt;em&gt;AssemblyInfo&lt;/em&gt; patched in &lt;em&gt;Additional Build Features&lt;/em&gt; so it will update the dll version in order to keep your files versioned.&lt;/p&gt;
&lt;p&gt;That's all you need to set for TeamCity to create NuGet packages.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Visual Studio configuration&lt;/h2&gt;
&lt;p&gt;Next we need to configure VS to get the package from TeamCity.&lt;/p&gt;
&lt;p&gt;In VS open &lt;em&gt;Tools &amp;gt; Library Package Manager &amp;gt; Package Manager Settings&lt;/em&gt;. Select the &lt;em&gt;Packages Sources &lt;/em&gt;and click the "+" to add a new sources. Give it a name and set the Source. If you haven't figured it out go into &lt;em&gt;TeamCity &amp;gt; Administrator &amp;gt; NuGetSettings &amp;gt; NuGet Server&lt;/em&gt; and get the URL, either Autenticated Feed URL or Public Feed URL, depending how you configured it.&lt;/p&gt;
&lt;p&gt;In order to add the common library to your project follow the same steps you do when you add a standard NuGet package to your project except you'll see now an additional repository - the one you&amp;rsquo;ve just created. That&amp;rsquo;s it &amp;ndash; you now have your own NuGet package repository and you can add it to all your projects.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Using NuGet without committing packages to source control&lt;/h2&gt;
&lt;p&gt;When you add the NuGet package to your solution it will be added to your source control. So all the dll files will be committed to the source control. Starting with NuGet version 2 you have the option to download the library when you compile so the missing libraries will be downloaded on demand instead of keeping them on the source control. In order to enable this in VS open &lt;em&gt;Tools &amp;gt; Library Package Manager &amp;gt; Package Manager Settings&lt;/em&gt; and select &lt;em&gt;General&lt;/em&gt;. Check the &lt;em&gt;Allow NuGet to download missing packages during build&lt;/em&gt;. This should be done on every machine. Next right click on the solution which uses the NuGet packages and select &lt;em&gt;Enable NuGet Package Restore&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;When you enable NuGet Package Restore a new .nuget folder will be created. It contains NuGet.exe file. It is executed during the build process to install the missing packages. This file should be added to source control. So if you have all your *.exe files ignored make sure NuGet.exe is not excluded, otherwise the build will fail.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;One of the best way of sharing your libraries is using NuGet packages. You need to setup a TeamCity configuration build and configure the Visual Studio to access it. This post describes the steps you need to follow.&lt;/p&gt;</description><pubDate>Sat, 21 Sep 2013 14:35:00 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/post/2013/07/15/Hosting-NuGet-in-TeamCity-and-consume-it-in-Visual-Studio</guid></item><item><title>Git versioning for .NET projects with TeamCity</title><link>http://www.ralbu.com:80/post/2013/03/28/Git-versioning-for-NET-projects-with-TeamCity</link><description>&lt;p&gt;TeamCity has a nice feature which allows to create a build number automatically with every build. For example, MyLib.dll has version 1.2.3.0. When configuring TeamCity in the &amp;ldquo;Build number format&amp;rdquo; the value specified like {0} will increase with every build. So if you set &amp;ldquo;Build number format&amp;rdquo; 1.2.3.{0} then the last number (revision number) will increase with every build.&lt;/p&gt;
&lt;p&gt;For a .NET project if you provide the AssemblyInfo patcher feature for your build configuration then the AssemblyVersion and AssemblyFileVersion will be updated automatically with the build number.&lt;/p&gt;
&lt;p&gt;This works well for the cases when only one number should be changed. But you might want to have two numbers updated with your build, build and revision values. With Subversion you can include the repository Revision number as part of the building number. Git doesn&amp;rsquo;t provide this number because each commit is represented by a SHA1 hash.&lt;/p&gt;
&lt;p&gt;The solution will be to take advantage of the number of commits since the most recent tag. This is made available through the &lt;a href="https://www.kernel.org/pub/software/scm/git/docs/git-describe.html"&gt;git describe&lt;/a&gt; command.&lt;/p&gt;
&lt;p&gt;This will work only if you have at least one tag in your repository and every time you need to change you version you need to create a new tag. Also you need to push your tag to the remote repository as it is not pushed automatically.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s add a new tag to your commit&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;"&gt;git tag v1.2&lt;/pre&gt;
&lt;p&gt;And use describe command&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;"&gt;git describe --tags --long&lt;/pre&gt;
&lt;p&gt;Will display&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;"&gt;v1.2-0-gb2d5397&lt;/pre&gt;
&lt;p&gt;The --tags flag allows to use lightweight tag and --long takes care to display the long format &amp;ndash; the tag, the number of commits and the abbreviated commit name.&lt;/p&gt;
&lt;p&gt;The 0 number represent the number of commits.&lt;/p&gt;
&lt;p&gt;The describe command works fine but what happens if a new tag is created and its purpose is not for versioning. To fix this will add the --match flag so your command will become:&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;"&gt;git describe --tags &amp;ndash;long --match v?.?&lt;/pre&gt;
&lt;p&gt;This will display only the tags which are in format v?.?, v1.2 for instance. If you want to keep your versioning tags differently, for example version1.2 then you need to change v?.? to version?.?&lt;/p&gt;
&lt;p&gt;That is all good but how can we use it with TeamCity? We will create a Powershell script which parses the output and creates the build number.&lt;/p&gt;
&lt;p&gt;In TeamCity &amp;ldquo;Runner type&amp;rdquo; is set as Powershell and in the &amp;ldquo;Script arguments&amp;rdquo; %build.number% is provided.&lt;/p&gt;
&lt;p&gt;Will use the following script&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;"&gt;Param ([string]$build_num)

$git_version = (git describe --tags --long --match v?.? | Select-String -pattern '(?&amp;lt;major&amp;gt;[0-9]+)\.(?&amp;lt;minor&amp;gt;[0-9]+)-(?&amp;lt;seq&amp;gt;[0-9]+)-(?&amp;lt;hash&amp;gt;[a-z0-9]+)').Matches[0].Groups

$git_describe = $git_version[0].Value

$version = [string]::Join('.', @(
  $git_version['major'],
  $git_version['minor'],
  $git_version['seq'],
  $build_num 
))

Write-Host "##teamcity[buildNumber '$version']"&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Line 1: reads the provided %build.number% from TeamCity&lt;/li&gt;
&lt;li&gt;Line 3: uses the git describe command and creates an object with all version parts&lt;/li&gt;
&lt;li&gt;Lines 7-12: create a version string based on the git tag and TeamCity&lt;/li&gt;
&lt;li&gt;Line 14: uses TeamCity service messages to pass the information to TeamCity&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This step should be added before the step where you compile your project.&lt;/p&gt;</description><pubDate>Thu, 28 Mar 2013 05:26:00 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/post/2013/03/28/Git-versioning-for-NET-projects-with-TeamCity</guid></item></channel></rss>