<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>TeamCity</title><link>http://www.ralbu.com:80/tags/teamcity</link><description>TeamCity</description><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 4. Deploying Azure Mobile Services</title><link>http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-4-deploying-azure-mobile-services</link><description>&lt;p&gt;In the &lt;a href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-3-build-azure-mobile-service-with-powershell-using-psake" target="_blank"&gt;previous post&lt;/a&gt; I explained how to run a set of steps including restoring NuGet packages, building and running Unit Tests using &lt;a href="https://github.com/psake/psake" target="_blank"&gt;psake&lt;/a&gt; with PowerShell.&lt;/p&gt;
&lt;p&gt;The last step in our pipeline is the deployment script. This post will be shorter than others because it describes only the deployment of Azure Mobile Services. Basically this deployment issue triggered me to write an entire set of blog posts. At the moment Microsoft doesn&amp;rsquo;t provide a way of deploying Azure Mobile Service from the command line. The only option you have is using Visual Studio. But you can&amp;rsquo;t achieve much automation using Visual Studio.&lt;/p&gt;
&lt;p&gt;I will create the deployment step in a separate script so we can use the same script when deploying on other environments. The script name is &lt;em&gt;deploy-package.ps1&lt;/em&gt; and it contains a few parameters.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;packageLocation&lt;/b&gt; &amp;ndash; this is the location where our package is stored. The location was defined during the build step. It was defined in &lt;em&gt;$artifactDirectory&lt;/em&gt; variable which in our case was set to &amp;ldquo;&lt;em&gt;[Root]\Artifacts&lt;/em&gt;&amp;rdquo;. We&amp;rsquo;ll configure this in TeamCity as well so we can reuse artifacts for deployments in other environments.&lt;/p&gt;
&lt;p&gt;The rest of parameters are not really straightforward, we need to extract them from the Mobile Service Publish Profile. In Azure Management Portal open your Mobile Service you want to deploy to and click on the Dashboard. There should be &amp;ldquo;Download publish profile&amp;rdquo; link. Click on it and download the profile. The profile file is an XML file. Open it in a text editor like Sublime or Notepad++ and format the XML to be easier to read. The profile contains two publishing methods: MSDeploy and FTP. We&amp;rsquo;ll look at the MSDeploy. Search for the MSDeploy in publishMethod attribute and that will be the publishProfile XML element we&amp;rsquo;ll be looking at.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;contentPath&lt;/b&gt; &amp;ndash; search for msdeploySite and that will be the value you need. It should have the form of &lt;i&gt;mobile$[MOBILE-SERVICE-NAME]&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;computerName&lt;/b&gt; &amp;ndash; This was a bit difficult to figure out because you don&amp;rsquo;t have the value in the publish profile file. We&amp;rsquo;ll construct the value from different parts. Search for &lt;i&gt;publishUrl&lt;/i&gt; in the profile file. My value is similar to this &lt;i&gt;waws-prod-dbx-xxx.publish.azurewebsites.windows.net:443&lt;/i&gt;. To construct the &lt;i&gt;computerName&lt;/i&gt; we&amp;rsquo;ll get the &lt;em&gt;publishUrl&lt;/em&gt; value till the port number, for example &lt;i&gt;waws-prod-dbx-xxx.publish.azurewebsites.windows.net&lt;/i&gt; and append this at the end &lt;i&gt;/msdeploy.axd?site=[deploySite]&lt;/i&gt; . Replace the deploySite with the &lt;i&gt;deploySite&lt;/i&gt; attribute value from the profile file. Also add &lt;em&gt;https:// &lt;/em&gt;in front. At the end you should have a value similar to this:&lt;/p&gt;
&lt;p&gt;&lt;i&gt;https://waws-prod-dbx-xxx.publish.azurewebsites.windows.net/msdeploy.axd?site=mobile$my-mobile-service&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;userName &lt;/b&gt;&amp;ndash; get the userName from the publish profile&lt;/p&gt;
&lt;p&gt;&lt;b&gt;password&lt;/b&gt; &amp;ndash; get the password value from the publish profile&lt;/p&gt;
&lt;p&gt;In order to deploy the mobile service we are going to use msdeploy application. You should have it installed on your machine but it&amp;rsquo;s missing from the Azure VM. Remote into the VM, download it from the &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=39277"&gt;http://www.microsoft.com/en-us/download/details.aspx?id=39277&lt;/a&gt; and install it.&lt;/p&gt;
&lt;p&gt;MsDeploy will be executed with these parameters&lt;/p&gt;
&lt;p&gt;msdeploy.exe -verb:sync -source:contentPath=[PACKAGE_LOCATION] -dest:ContentPath=[CONTENT_PATH],ComputerName=[COMPUTER_NAME],UserName=[USER_NAME],Password=[PASSWORG],AuthType='Basic'&lt;/p&gt;
&lt;p&gt;This is the source code which will deploy the package&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;function DeployPackage
{
    Param(
        [String]$packageLocation,
        [String]$contentPath,
        [String]$computerName,
        [String]$userName,
        [String]$password
    )

    $webDeployExePath = "C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\"

    $msdeploy = "$webDeployExePath\msdeploy.exe"
    if (!(Test-Path $msdeploy)) {
        throw "msdeploy.exe could not be found on this machine. MsDeploy location: $msdeploy"
    }

    "***** Start deploying the package from loction: $packageLocation *****"

    $arg1 = "-verb:sync" 
    $arg2 = "-source:contentPath=$packageLocation"
    $arg3 = "-dest:ContentPath='$contentPath',ComputerName='$computerName',UserName='$userName',Password='$password',AuthType='Basic'"

    &amp;amp; $msdeploy $arg1 $arg2 $arg3 $arg4
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now you should be able to build and deploy the Mobile Service to Azure instance from your machine. In the next post we&amp;rsquo;ll configure TeamCity to do this for us.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-3-build-azure-mobile-service-with-powershell-using-psake" target="_blank"&gt;&amp;lt; Previous&lt;/a&gt;&lt;/p&gt;</description><pubDate>Wed, 22 Jul 2015 05:02:23 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-4-deploying-azure-mobile-services</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>Azure Mobile Service deployment with Team City part 2. Configure TeamCity NuGet Server</title><link>http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-2-configure-teamcity-nuget-server</link><description>&lt;p&gt;In the previous &lt;a target="_blank" title="post" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-1-team-city-installation"&gt;post&lt;/a&gt; I explained how to install TeamCity on Azure and configure it.&lt;/p&gt;
&lt;p&gt;In this post I will create a TeamCity configuration which will publish to a NuGet Server hosted in TeamCity.&lt;/p&gt;
&lt;p&gt;You can find the source code used by these series of post at &lt;a title="https://github.com/ralbu/TeamCityAzure" href="https://github.com/ralbu/TeamCityAzure"&gt;https://github.com/ralbu/TeamCityAzure&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Common project&lt;/h2&gt;
&lt;p&gt;As this is a fresh installation of TeamCity there are no projects. Let&amp;rsquo;s create one. I will name it User Management. It will contain two configurations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Common &amp;ndash; a NuGet package used by the main project (User Management)&lt;/li&gt;
&lt;li&gt;User Management &amp;ndash; an Azure Mobile Service project&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Click the Create project button&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p21_2.png"&gt;&lt;img title="p21" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p21" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p21_thumb.png" height="200" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Enter the Name of the project and optionally the description 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_1311A/p22_2.png"&gt;&lt;img title="p22" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p22" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p22_thumb.png" height="256" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After the project was created click on the Create build configuration button&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p23_2.png"&gt;&lt;img title="p23" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p23" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p23_thumb.png" height="756" border="0" width="1024" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The first project configuration is our Common library hosted on a NuGet server. We&amp;rsquo;ll use the TeamCity NuGet plugin to host our NuGet Common package.&lt;/p&gt;
&lt;p&gt;Enter the required data 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_1311A/p24_2.png"&gt;&lt;img title="p24" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p24" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p24_thumb.png" height="291" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the next step we configure the source control. For this set of tutorials I host the project to GitHub in a public repository. As this is a public repository I use Anonymous as authentication method. There are other options you can choose from, like Password or Private Key. Click Test Connection and if everything is ok click Create.&lt;/p&gt;
&lt;p&gt;Both projects &amp;ndash; NuGet package and Azure Mobile Service used in this set of blog posts are under the same GitHub repository so I will reuse this VCS root in both projects.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p26_2.png"&gt;&lt;img title="p26" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p26" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p26_thumb.png" height="723" border="0" width="1024" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Prerequisites for running builds&lt;/h2&gt;
&lt;p&gt;Next we&amp;rsquo;ll create build configurations but before that we need to install the necessary software and configure NuGet server on TeamCity.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We are not going to install Visual Studio on the build machine, although that will be easier. We&amp;rsquo;ll install only the minimum which is needed to build our projects. Remote into the VM and from &lt;a href="https://www.visualstudio.com/en-us/downloads"&gt;https://www.visualstudio.com/en-us/downloads&lt;/a&gt; download &amp;ldquo;Microsoft Build Tools&amp;rdquo; and install it.&lt;/li&gt;
&lt;li&gt;You might also need to install &amp;ldquo;.NET Framework 4.5.1 Developer Pack&amp;rdquo;. If you want to have a clean machine I would skip this step and install it later if the build fails. I had to install it because of the xUnit framework. If you are not sure you need &amp;ldquo;.NET Framework 4.5.1 Developer Pack&amp;rdquo; then first start with &amp;ldquo;.NET Framework 4.5&amp;rdquo; installation.&lt;/li&gt;
&lt;li&gt;In order to deploy our mobile services we&amp;rsquo;ll be using Web Deploy. Install it from this location: &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=39277"&gt;http://www.microsoft.com/en-us/download/details.aspx?id=39277&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You&amp;rsquo;ll need to restart the TeamCity agent. Open the Services application and search for Team City Build Agent and restart it.&lt;/p&gt;
&lt;p&gt;We need to manually copy the next two folders&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Copy the folder C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\WebApplications to the same location of TeamCity server. The reason for doing that is because we don&amp;rsquo;t have Visual Studio installed on the TeamCity machine. The build process uses targets from Microsoft.WebApplication.targets file to build the Web Application.&lt;/li&gt;
&lt;li&gt;Copy the folder C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web to TeamCity machine. Make sure you copy this folder. These targets are used in generating packages. If you don&amp;rsquo;t have this targets it will build the solution but it will not create a package which is used in deployment. It is not easy to figure out if you missed it because the solution will build successfully but the package will not be created and it won&amp;rsquo;t give you any error or warning.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Configure NuGet Server&lt;/h2&gt;
&lt;p&gt;In the TeamCity web page, click on the Administration and then in the left hand side under Integration click NuGet. On the NuGet Server tab click Enable button. We are going to use authenticated feed and not the public one. Copy the link to the authenticated feed URL, we&amp;rsquo;ll use it later. Click on the NuGet.exe tab and then on Fetch NuGet button. Select the NuGet version and select Set as Default. At the time of this writing the latest NuGet is 2.8.5.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p27_2.png"&gt;&lt;img title="p27" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p27" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p27_thumb.png" height="641" border="0" width="1024" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Creating build configurations&lt;/h2&gt;
&lt;p&gt;In this step we&amp;rsquo;ll create our first build configuration. As the first step we&amp;rsquo;ll build our solution.&lt;/p&gt;
&lt;p&gt;Click on the Build Steps in the Build Configuration Settings and click Add build step&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p28_2.png"&gt;&lt;img title="p28" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p28" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p28_thumb.png" height="188" border="0" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;From the New Build Step page select Visual Studio (sln) Runner type and provide the rest of the settings as below and click Save.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p29_2.png"&gt;&lt;img title="p29" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p29" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p29_thumb.png" height="547" border="0" width="1024" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Click the Run button if you want to make sure that everything is ok at this step.&lt;/p&gt;
&lt;p&gt;In the next step we&amp;rsquo;ll add the build configuration to create a NuGet package and publish it on TeamCity&amp;rsquo;s NuGet server.&lt;/p&gt;
&lt;p&gt;First of all make sure you have the NuGet spec file. If you don&amp;rsquo;t then the fastest way of generating it is to open the command line where your .csproj file is located and run:&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;nuget spec&lt;/pre&gt;
&lt;p&gt;Open it and adjust it accordingly.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m not going to go in details about this step, just have a look at the settings below, and if you want to find out more about it then go to my other blog &amp;ndash; &lt;a href="http://ralbu.com/post/2013/07/15/Hosting-NuGet-in-TeamCity-and-consume-it-in-Visual-Studio" target="_blank"&gt;Hosting NuGet in TeamCity and consume it in Visual Studio&lt;/a&gt; where I explained all the settings.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p210_2.png"&gt;&lt;img title="p210" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p210" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p210_thumb.png" height="768" border="0" width="970" /&gt;&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_1311A/p211_2.png"&gt;&lt;img title="p211" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="p211" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-Mobile-Service-deployment-with-Te_1311A/p211_thumb.png" height="589" border="0" width="1024" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Click Save and this is how you would configure a NuGet Server. In the next blog post I will describe how to create the main project configuration as a PowerShell script and configure it in TeamCity&lt;/p&gt;</description><pubDate>Mon, 13 Jul 2015 05:00:01 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-2-configure-teamcity-nuget-server</guid></item><item><title>Azure Mobile Service deployment with Team City part 1. Team City Installation</title><link>http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-1-team-city-installation</link><description>&lt;p&gt;In these series of blog posts I will explain how to host a TeamCity server on an Azure Virtual Machine, configure it and create TeamCity configuration to build and 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-1-team-city-installation"&gt;Azure Mobile Service deployment with Team City part 1. Team City Installation (this article)&lt;/a&gt;&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;Azure Mobile Service deployment with Team City part 2. Configure TeamCity NuGet Server&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a target="_self" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-3-build-azure-mobile-service-with-powershell-using-psake"&gt;Azure Mobile Service deployment with Team City part 3. Build Azure Mobile Service with PowerShell using psake&lt;/a&gt;&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;Azure Mobile Service deployment with Team City part 4. Deploying Azure Mobile Services&lt;/a&gt;&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;Azure Mobile Service deployment with Team City part 5. Configuring Mobile in TeamCity&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a target="_self" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-6-integrate-specflow-with-teamcity"&gt;Azure Mobile Service deployment with Team City part 6. Integrate SpecFlow with TeamCity&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a target="_self" href="http://ralbu.com/azure-mobile-service-deployment-with-team-city-part-7-deployment-to-test-environment"&gt;Azure Mobile Service deployment with Team City part 7. Deployment to Test environment&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Recently Azure introduced a new concept for Mobile Services &amp;ndash; Mobile App. You can access it in the &lt;a href="http://portal.azure.com" target="_blank"&gt;Azure Preview Portal&lt;/a&gt;. This blog explains Azure Mobile Services which can be accessed at &lt;a href="http://manage.windowsazure.com" target="_blank"&gt;Azure Management Portal&lt;/a&gt;. The reason for doing this is that the Mobile App is still in preview and for the current Mobile Service Microsoft doesn&amp;rsquo;t provide an easy way of doing continuous deployment. The only way you can deploy it is by using Visual Studio. There are no API either for &lt;a href="https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure" target="_blank"&gt;Azure PowerShell&lt;/a&gt; or for &lt;a href="https://azure.microsoft.com/en-us/documentation/articles/xplat-cli" target="_blank"&gt;Command Line Interface&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I will use &lt;a href="http://portal.azure.com" target="_blank"&gt;Azure Preview Portal&lt;/a&gt; every time apart from the time when there are operations which I can&amp;rsquo;t do using it. In this case I will use &lt;a href="http://manage.windowsazure.com" target="_blank"&gt;Azure Management Portal&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;All the examples and UI screenshots are based on TeamCity version 9.0.4.&lt;/p&gt;
&lt;p&gt;These series will walk you through all the steps from zero to a fully working Continuous Integration and Deployment on Dev and Test environment.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Creating an Azure Virtual Machine&lt;/h2&gt;
&lt;p&gt;Open the Azure Preview Portal and click the &amp;ldquo;+&amp;rdquo; button, select Compute and from the list select Windows Server 2012 R2 Datacenter.&lt;/p&gt;
&lt;p&gt;Provide all the details on the opened blade.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Host Name &amp;ndash; name of your VM.&lt;/li&gt;
&lt;li&gt;User Name &amp;ndash; user name you&amp;rsquo;ll use to log in to the Remote Machine&lt;/li&gt;
&lt;li&gt;Password &amp;ndash; password to be used to log into the Remote Machine&lt;/li&gt;
&lt;li&gt;Pricing Tier &amp;ndash; select the size of your machine. Check the prices on this page: &lt;a href="http://azure.microsoft.com/en-gb/pricing/details/virtual-machines"&gt;http://azure.microsoft.com/en-gb/pricing/details/virtual-machines&lt;/a&gt;. The cheapest machine is Basic Tier A0. Even if you do this as a PoC this machine is not powerful enough. You&amp;rsquo;ll spend too much time waiting for the installation of TeamCity and the machine will be too slow. Basic A1 is OK but I would recommend Basic A2. You can start with that and later you can upgrade the machine.&lt;/li&gt;
&lt;li&gt;Resource Group &amp;ndash; this is a container to help you manage a set of resources, like provisioning them. In this I will create a new Resource Group&lt;/li&gt;
&lt;li&gt;Subscription &amp;ndash; select your subscription&lt;/li&gt;
&lt;li&gt;Location &amp;ndash; choose a location, preferably the same location where all your services are&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Click Create and after less than 10 minutes you&amp;rsquo;ll have the machine up and running.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/vm_2.png"&gt;&lt;img title="vm" style="display: inline;" alt="vm" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/vm_thumb.png" height="988" width="1000" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;TeamCity Installation&lt;/h2&gt;
&lt;p&gt;After the machine was provisioned, on the Azure Management Portal open the new created VM instance and click on the Connect button. As it stands now, if you download the Remote Desktop Connection file from the Azure Preview Portal you&amp;rsquo;ll have to enter the machine name manually.&lt;/p&gt;
&lt;p&gt;It will download a Remote Desktop Connection file. Double click the file and then enter the user name and password you provided when you created the VM. After you&amp;rsquo;ve logged in, open the Internet Explorer and download &lt;a href="https://www.jetbrains.com/teamcity" target="_blank"&gt;TeamCity&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now let&amp;rsquo;s install TeamCity on that VM. I will skip the obvious steps where you need to accept license, etc.&lt;/p&gt;
&lt;p&gt;TeamCity installation directory &amp;ndash; this is where the TeamCity server is installed. It will contain the TeamCity configuration, binaries. I will keep the default value c:\TeamCity&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci1_2.png"&gt;&lt;img title="tci1" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="tci1" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci1_thumb.png" border="0" height="484" width="621" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;On the next step we&amp;rsquo;ll install all the components.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci2_2.png"&gt;&lt;img title="tci2" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="tci2" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci2_thumb.png" border="0" height="484" width="621" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Next is the TeamCity Data Directory. It is important to select the right Data Directory location. TeamCity stores configuration settings, artifacts, build logs, etc. By default it stores all the configuration settings. It is recommended that you configure TeamCity to store all the configuration settings in the Database. Do make sure you backup this folder regularly. Due to the fact that Data Directory stores all the build logs and artifacts and can grow very large it is recommended to select a non-system disk. For the sake of this demo I will leave the default value: C:\ProgramData\JetBrains\TeamCity&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tc3_2.png"&gt;&lt;img title="tc3" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="tc3" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tc3_thumb.png" border="0" height="484" width="621" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Will keep the default port 80&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci4_2.png"&gt;&lt;img title="tci4" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="tci4" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci4_thumb.png" border="0" height="484" width="621" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The TeamCity server installation is now finished.&lt;/p&gt;
&lt;p&gt;Next we&amp;rsquo;ll configure the Build Agent.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci5_2.png"&gt;&lt;img title="tci5" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="tci5" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci5_thumb.png" border="0" height="438" width="644" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I will use System Account to run TeamCity but you might want to select a user account with less privileges.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci6_2.png"&gt;&lt;img title="tci6" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="tci6" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci6_thumb.png" border="0" height="484" width="621" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For the Agent we&amp;rsquo;ll select a user account. I will explain the reason for that later. Select the account you used to log into VM or if you want you can create a new one.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci6-1_2.png"&gt;&lt;img title="tci6-1" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="tci6-1" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci6-1_thumb.png" border="0" height="484" width="621" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And will start all the services.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci7_2.png"&gt;&lt;img title="tci7" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="tci7" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci7_thumb.png" border="0" height="484" width="621" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After clicking the Next button it will finish the configuration, start the services and open the default page: &lt;a href="http://localhost"&gt;http://localhost&lt;/a&gt;. Click on the Proceed button and next select the data base type. I will select Internal (HSQLDB) for the sake of this tutorial but in your case it depends on the type of server. If you just want to try things out and are not worried about losing configurations use HSQLDB, otherwise you&amp;rsquo;ll need a separate database. Depending on which type you select you&amp;rsquo;ll have more configuration to enter. Click Proceed and wait till TeamCity is starting up. Accept the license agreement and click Continue.&lt;/p&gt;
&lt;p&gt;TeamCity will ask you to create an administrator account. Enter the user name and password and click Create Account.&lt;/p&gt;
&lt;h2&gt;&amp;nbsp;&lt;/h2&gt;
&lt;h2&gt;Configure TeamCity to be accessible from web&lt;/h2&gt;
&lt;p&gt;Now that TeamCity is up and running there a few steps to be done to be able to access TeamCity from the web. First we need to setup an endpoint to direct inbound traffic to the TeamCity VM. Open the VM in Azure Preview Portal, select All settings and click on the Endpoints. Provide a name, select TCP from the Protocol list, and enter public and private ports. I used 80 for both. The public port is used by Azure load balancer. The private port is used by the VM to listen for the incoming traffic. It should have the same value we set when installed TeamCity.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci8_2.png"&gt;&lt;img title="tci8" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="tci8" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci8_thumb.png" border="0" height="750" width="1000" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We need to configure TeamCity VM firewall to allow incoming traffic for the TCP protocol and private port corresponding to the endpoint configuration. Remote into the VM and open Server Manager &amp;gt; Tools &amp;gt; Windows Firewall with Advanced Security. Select the Inbound Rules, right click and click &amp;ldquo;New Rule&amp;hellip;&amp;rdquo; Select Port, TCP rule and port number. It should be the same port you used when you installed TeamCity and private port for endpoint configuration. Allow for All connections and give it a name.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci9_2.png"&gt;&lt;img title="tci9" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" alt="tci9" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Azure-deployment-with-Team-City-part-1_12A46/tci9_thumb.png" border="0" height="744" width="1000" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now fire up your browser and you should be able to open TeamCity login page. If you are not sure what&amp;rsquo;s the name of the TeamCity VM go to the Azure Preview Portal and check the DNS name in the Essentials area.&lt;/p&gt;
&lt;p&gt;This finishes TeamCity installation and configuration. In the next part we&amp;rsquo;ll create TeamCity build configuration and configure a NuGet Server.&lt;/p&gt;</description><pubDate>Wed, 08 Jul 2015 04:00:00 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/azure-mobile-service-deployment-with-team-city-part-1-team-city-installation</guid></item><item><title>TeamCity Build Parameters for PowerShell</title><link>http://www.ralbu.com:80/teamcity-build-parameters-for-powershell</link><description>&lt;p&gt;In this article I will describe how you can add custom parameters to your TeamCity build configuration and read them in Powershell. Although adding parameters is not difficult and it is documented ok it is not really straightforward and you'd need a few trials until get it right.&lt;/p&gt;
&lt;p&gt;Let's say we have a web project which needs to be deployed. For this purpose we'll add two parameters:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A boolean with the name &lt;em&gt;deploy&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;A path where the service will be deployed.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is just an example of how to set two parameters and read them in powershell. You can use this for your own scenarios, not just for setting up deployment&lt;/p&gt;
&lt;p&gt;Open your TeamCity configuration project and on the Configuration Steps click the Build Parameters. Click 'Add new parameter' button and provide the name 'Deploy'. Select Configuration parameter from the &lt;em&gt;Kind&lt;/em&gt; drop down. Type &lt;em&gt;false&lt;/em&gt; in the &lt;em&gt;Value &lt;/em&gt;field. Click on the &lt;em&gt;Edit&amp;hellip;&lt;/em&gt; button, give it a label and description. In &lt;em&gt;Type &lt;/em&gt;select Checkbox and set &lt;em&gt;Checked &lt;/em&gt;value to &lt;em&gt;true &lt;/em&gt;and &lt;em&gt;Unchecked &lt;/em&gt;to &lt;em&gt;false&lt;/em&gt;. Click Save.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="/Media/Default/Windows-Live-Writer/TeamCity-Build-Parameters-for-Powershell_13BFB/Edit%20Parameter_2.png" height="498" width="486" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Add new parameter for the deployment path. I named it &lt;em&gt;DeployPath&lt;/em&gt; with &lt;em&gt;Text Type &lt;/em&gt;and Allowed&lt;em&gt; Value&lt;/em&gt; to &lt;em&gt;Any&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="/Media/Default/Windows-Live-Writer/TeamCity-Build-Parameters-for-Powershell_13BFB/Edit%20DeployPath_2.png" height="480" width="483" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Next we need to add a PowerShell script. In the TeamCity &lt;em&gt;Build Steps&lt;/em&gt; add a new build and set the type drop down to Powershell.&lt;/p&gt;
&lt;p&gt;Create a PowerShell file on your disk and set the path to that file (in the &lt;em&gt;Script file &lt;/em&gt;text box).&lt;/p&gt;
&lt;p&gt;In the &lt;em&gt;Script arguments &lt;/em&gt;add the following:&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;-deploy:%Deploy% 

-deployPath:%DeployPath% 
&lt;/pre&gt;
&lt;p&gt;Open the PowerShell file you&amp;rsquo;ve created on the hard disck and add the following lines.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;param 

( 

[Parameter(Mandatory=$false)] [String]$deploy, 

[Parameter(Mandatory=$false)] [String]$deployPath 

) 

Write-Host "Deploy " + $deploy 

Write-Host "Deploy path is: " + $deployPath 

&lt;/pre&gt;
&lt;p&gt;Now you need to add the part which will deploy your web site or do whatever you need.&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="/Media/Default/Windows-Live-Writer/TeamCity-Build-Parameters-for-Powershell_13BFB/PowerShell%20step_2.png" height="643" width="1024" /&gt;&lt;/p&gt;
&lt;p&gt;You can read the TeamCity parameters inside PowerShell but I prefer to set them outside of PowerShell and feed to PowerShell as command parameters. In this way your script doesn't depend on TeamCity and you can test it locally.&lt;/p&gt;</description><pubDate>Tue, 28 Jan 2014 22:48:00 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/teamcity-build-parameters-for-powershell</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>