<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Powershell</title><link>http://www.ralbu.com:80/tags/powershell</link><description>Powershell</description><item><title>Become a Git command line guru</title><link>http://www.ralbu.com:80/become-a-git-command-line-guru</link><description>&lt;p&gt;Git became one of the widely used Source Control System. If you work on a Windows machine you may rely on your IDE or other tools like &lt;a href="https://desktop.github.com" target="_blank"&gt;GitHub Desktop&lt;/a&gt; or &lt;a href="https://www.sourcetreeapp.com" target="_blank"&gt;Atlassian's SourceTree&lt;/a&gt; to work with git. But in order to get all the power git offers you need to start using git from the command line. Don't get put off by the fact that git on windows is limited. With the right tools and configurations you'll enjoy it and finally you'll start liking it.&lt;br /&gt;The default command line solution for git is to use Git Bash but we'll use &lt;a href="https://conemu.github.io/" target="_blank"&gt;ConEmu&lt;/a&gt; with &lt;a href="https://github.com/dahlbyk/posh-git" target="_blank"&gt;PowerShell Posh Git&lt;/a&gt; module. You'll be very pleased how it works.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Installation&lt;/h1&gt;
&lt;h2&gt;Git&lt;/h2&gt;
&lt;p&gt;If you have not installed git yet let&amp;rsquo;s do it now. Either download it from &lt;a href="https://git-scm.com/download"&gt;https://git-scm.com/download&lt;/a&gt; or run chocolately:&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;choco install git.install&lt;/pre&gt;
&lt;p&gt;You can add &amp;ndash;&lt;em&gt;notSilent &lt;/em&gt;in the command line in order to have the installation wizard if you want to provide different options.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;ConEmu&lt;/h2&gt;
&lt;p&gt;Install ConEmu from &lt;a href="https://github.com/Maximus5/ConEmu"&gt;https://github.com/Maximus5/ConEmu&lt;/a&gt; or run chocolately:&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;choco install conemu&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Posh Git&lt;/h2&gt;
&lt;p&gt;After ConEmu was installed we need to install Posh Git&lt;/p&gt;
&lt;p&gt;Run&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;choco install poshgit&lt;/pre&gt;
&lt;p&gt;Or go to the web site &lt;a href="https://github.com/dahlbyk/posh-git"&gt;https://github.com/dahlbyk/posh-git&lt;/a&gt; and follow the instructions&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When you install poshgit make sure that you have git installed already and the Environment path for git was set before opening the PowerShell. If for some reasons you don't want to have git path in the Environment variable then add the following to your &lt;em&gt;c:\Users\[UserName]\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1&lt;/em&gt; file.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;$env:path += ";" + (Get-Item "Env:ProgramFiles(x86)").Value + "\Git\bin"&lt;/pre&gt;
&lt;p&gt;Replace &lt;em&gt;ProgramFiles(x86)&lt;/em&gt; with &lt;em&gt;ProgramFiles &lt;/em&gt;if you have installed git in &lt;em&gt;Program Files.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The installation of posh-git will add the following in the Microsoft.PowerShell_profile.ps1&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;# Load posh-git example profile
. 'C:\tools\poshgit\dahlbyk-posh-git-869d4c5\profile.example.ps1'&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;ConEmu Configuration&lt;/h1&gt;
&lt;p&gt;Open ConEmu and navigate to a git repository. In my case, I've opened xunit. As you can see from the image the command line has this information: I am on the master branch, 1 file added and two edited.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Become-a-Git-command-line-guru_AE57/git-cmd_2.png"&gt;&lt;img title="git-cmd" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="git-cmd" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Become-a-Git-command-line-guru_AE57/git-cmd_thumb.png" border="0" height="55" width="640" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We can add task bar jump list in ConEmu. In this case when I right click on the ConEmu in the task bar it will open a PowerSell console with poshgit at that location.&lt;/p&gt;
&lt;p&gt;Click on the icon on the left hand side of the ConEmu and select &lt;strong&gt;Settings&amp;hellip;&lt;/strong&gt; and then &lt;strong&gt;Startup &amp;gt; Tasks&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Become-a-Git-command-line-guru_AE57/conemu-menu_2.png"&gt;&lt;img title="conemu-menu" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="conemu-menu" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Become-a-Git-command-line-guru_AE57/conemu-menu_thumb.png" border="0" height="484" width="183" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;By default every item has &lt;strong&gt;Taskbar jump lists &lt;/strong&gt;checked. This means that all the items from the list will appear in Task bar list. We don't need to have all of them, so go though everyone and deselect what you don't need.&lt;/p&gt;
&lt;p&gt;The list in the &lt;strong&gt;Predefined&lt;/strong&gt; tasks contains all tabs you can open when creating a new Console. Let&amp;rsquo;s create one which will open PowerShell with poshgit in C:\Projects:&lt;/p&gt;
&lt;p&gt;Click the + button and add the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Name &amp;ndash; let&amp;rsquo;s name it &lt;strong&gt;Projects.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Task parameters - a path where you want the console to open, for example: &lt;em&gt;/dir "c:\Projects&lt;/em&gt;"&lt;/li&gt;
&lt;li&gt;Start console: &lt;em&gt;powershell.exe&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Click Up to move it to a desired location.&lt;/p&gt;
&lt;p&gt;Click Save settings with Shift key pressed because we don&amp;rsquo;t want to close the dialog yet.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Become-a-Git-command-line-guru_AE57/task-configuration_2.png"&gt;&lt;img title="task-configuration" style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" alt="task-configuration" src="http://www.ralbu.com/Media/Default/Windows-Live-Writer/Become-a-Git-command-line-guru_AE57/task-configuration_thumb.png" border="0" height="439" width="644" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the next step we'll add our new created Task to the Task bar jump list. Go to the &lt;em&gt;Main &amp;gt; Task&lt;/em&gt; bar. At the bottom of the window check &lt;strong&gt;Add ConEmu tasks &lt;/strong&gt;and click &lt;strong&gt;Update Now!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Click Save settings and we're done with the ConEmu settings. Now when you right click on Task bar you can open a new ConEmu instance directly into you Git local repository.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Git colours&lt;/h1&gt;
&lt;p&gt;Let's set a few colours in Git. If you use PowerShell colour scheme in ConEmu (I prefer ConEmu scheme) then the text in the default red colour will be difficult to read on the blue background. You fix this by adding the following in the &lt;em&gt;Microsoft.PowerShell_profile.ps1&lt;/em&gt; file.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;$global:GitPromptSettings.WorkingForegroundColor&amp;nbsp;&amp;nbsp;&amp;nbsp; = [ConsoleColor]::DarkGray&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;At this point all the PowerShell configuration is done. But I don't like the default git colours so I will update a few colours for git. This is nothing to do with PowerShell and this changes will apply to Git Bash as well.&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;git config --global color.status.added "green normal bold"
git config --global color.status.header "cyan normal bold"
git config --global color.status.updated "green normal bold"
git config --global color.status.changed "cyan"
git config --global color.branch.remote "blue normal bold"
git config --global color.branch.current "green normal bold"
git config --global color.branch.local "green dim"&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;git configuration&lt;/h1&gt;
&lt;h2&gt;Store git credentials&lt;/h2&gt;
&lt;p&gt;An easy way to store git credentials so you don&amp;rsquo;t have to type them every time is to use &lt;strong&gt;Git Credential Manager for Windows&lt;/strong&gt;, download it from &lt;a href="https://github.com/Microsoft/Git-Credential-Manager-for-Windows"&gt;https://github.com/Microsoft/Git-Credential-Manager-for-Windows&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Compare configuration&lt;/h2&gt;
&lt;p&gt;Before committing my files I like to compare my local changes with the remote version. I do that using &lt;a href="http://www.scootersoftware.com/" target="_blank"&gt;Beyond Compare&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I run the comparison from the command line:&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;git difftool&lt;/pre&gt;
&lt;p&gt;And configure git to use Beyond Compare:&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;git config --global merge.tool bc
git config --global mergetool.bc.path "c:/Program Files/Beyond Compare 4/bcomp.exe"
git config --global difftool.prompt false
&lt;/pre&gt;
&lt;p&gt;And the last step, I don&amp;rsquo;t want to write &lt;em&gt;difftool&lt;/em&gt; every time so let&amp;rsquo;s create an alias:&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;git config --global alias.dt difftool&lt;/pre&gt;
&lt;p&gt;Now it is just enough to type &lt;em&gt;dt&lt;/em&gt; and it will run the comparer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;As you can see there&amp;rsquo;s enough work to do in order to have a proper git command line on Windows. But you don&amp;rsquo;t have to configure everything. The most important thing is ConEmu and poshgit.&lt;/p&gt;</description><pubDate>Tue, 26 Jul 2016 05:02:37 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/become-a-git-command-line-guru</guid></item><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>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 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 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>PowerShell with Visual Studio</title><link>http://www.ralbu.com:80/powershell-with-visual-studio</link><description>&lt;p&gt;I started doing more and more PowerShell recently to automate provisioning environments on Azure and for CI &amp;amp; CD. I use Sublime for my editing - it's the best editor I've used but what I miss is a good vim plugin - or perhaps I haven't found that one. I use &lt;a href="https://visualstudiogallery.msdn.microsoft.com/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329" target="_blank"&gt;vim editor&lt;/a&gt; with my Visual Studio 2013.&lt;/p&gt;
&lt;p&gt;Visual Studio might sound like not the tool for writing PowerShell scripts but with the right plugin will make your life easier.&lt;/p&gt;
&lt;p&gt;Here you install Visual Studio plugin: &lt;a href="https://visualstudiogallery.msdn.microsoft.com/c9eb3ba8-0c59-4944-9a62-6eee37294597" target="_blank"&gt;https://visualstudiogallery.msdn.microsoft.com/c9eb3ba8-0c59-4944-9a62-6eee37294597&lt;/a&gt;. You get the intellisense support, debugging and even Unit Testing integration with &lt;a href="https://github.com/pester/Pester" target="_blank"&gt;Pester&lt;/a&gt;. In order to do this you need to use a PowerShell project. Usually I only need to edit my PowerShell scripts and I like to have the list of folders and files like you have with Visual Studio project or solution. There isn't a way in Visual Studio to open just a folder as you have in Sublime. The closest way of doing that is open File &amp;gt; Open &amp;gt; Web Site&amp;hellip; Select File System and select the folder you want to open.&lt;/p&gt;
&lt;p&gt;If you're developer and Visual Studio is your main IDE then this will be a nice addition to your Visual Studio tool set.&lt;/p&gt;</description><pubDate>Sat, 20 Jun 2015 05:02:26 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/powershell-with-visual-studio</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>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>