<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>NuGet</title><link>http://www.ralbu.com:80/tags/nuget</link><description>NuGet</description><item><title>Issue to be aware of when restoring NuGet packages for the code hosted in git repository of Visual Studio Team Services aka VSO</title><link>http://www.ralbu.com:80/vsts-git-repo-issue</link><description>&lt;p&gt;&lt;br /&gt;I came across this issue a few times with different developers so I thought I will write about it to save time for others. When you think about it then there's nothing wrong or mysterious about it but you may end up spending lots of time on it without realising what's wrong.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;If you create a new repository with a whitespace, like &lt;em&gt;&lt;strong&gt;My repository &lt;/strong&gt;&lt;/em&gt;then when you clone it:&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;git clone my.visualstudio.com/DefaultCollection/_git/My%20repository&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It will create a new folder with the name &lt;strong&gt;&lt;em&gt;My%20repository&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Everything is correct here, you can't have a space in an URL but if you open the solution in visual studio and build it you'll get errors like:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;span style="color: #ff0000;" color="#ff0000"&gt;The remote server returned an error: (401) Unauthorized&lt;/span&gt; or &lt;span style="color: #ff0000;" color="#ff0000"&gt;This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;The simplest solution is to rename the folder by removing &lt;strong&gt;&lt;em&gt;%20&lt;/em&gt;&lt;/strong&gt; or set a name when you clone it, like&lt;/p&gt;
&lt;pre class="brush: bash;"&gt;git clone [url] [Name]&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As I said, this is not an issue but easy to miss if you don't pay attention. Next time when you can't restore NuGet packages, start with checking where the repository was cloned.&lt;/p&gt;</description><pubDate>Wed, 25 Nov 2015 09:46:21 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/vsts-git-repo-issue</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>Create NuGet packages using AppVeyor</title><link>http://www.ralbu.com:80/create-nuget-packages-using-appveyor</link><description>&lt;p&gt;This blog explains how to create a NuGet package and use AppVeyor as a continuous integration and deployment tool.&lt;/p&gt;
&lt;p&gt;I found out about &lt;a href="http://www.appveyor.com/"&gt;AppVeyor&lt;/a&gt; some time ago from Scott's blog - "&lt;a href="http://www.hanselman.com/blog/AppVeyorAGoodContinuousIntegrationSystemIsAJoyToBehold.aspx"&gt;AppVeyor - A good continuous integration system is a joy to behold&lt;/a&gt;". Usually I use TeamCity running on a VM so I didn't have a chance to try it out until recently when I built a &lt;a href="https://www.nuget.org/packages/RandomUser"&gt;NuGet package&lt;/a&gt; to generate random users. The NuGet package is based on the &lt;a href="https://randomuser.me"&gt;https://randomuser.me&lt;/a&gt; API &amp;ndash; a free API to generate random user data. You would use it in prototyping, testing or filling your database with proper user names, pictures, etc.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.appveyor.com/"&gt;AppVeyor&lt;/a&gt; is a cloud based continuous integration and delivery service for .NET. It is free for open source projects. It has everything you need and it is really easy to set up. It has a nice Web UI where you configure your build and deployment settings but in this post I will explain the minimum configuration you need to publish a NuGet package using the appveyor.yml file. The reason I prefer to keep my configurations in a file rather than using the UI is that I can version it and when I break something I can fix it fast just by checking the differences in the file.&lt;/p&gt;
&lt;p&gt;Every AppVeyor configuration can contain an appveyor.yml file in the root folder. If you have the file and also configure the UI then the YAML file will override the UI settings unless you explicitly disable it in &lt;i&gt;Ignore appveyor.yml &lt;/i&gt;settings in the UI.&lt;/p&gt;
&lt;p&gt;AppVeyor also has the option to host NuGet packages. Before pushing the NuGet package to &lt;a href="https://www.nuget.org"&gt;https://www.nuget.org&lt;/a&gt; I use that to test my packages.&lt;/p&gt;
&lt;p&gt;Here's the full YAML file. As you can see, it is self-descriptive and I will explain only the settings which are not clear from the first glance or might be confusing.&lt;/p&gt;
&lt;pre class="brush: text;"&gt;version: 0.9.{build}

assembly_info:
  patch: true
  file: AssemblyInfo.cs
  assembly_version: '{version}'
  assembly_file_version: '{version}'
  assembly_informational_version: '{version}'

platform: Any CPU

configuration: Release

build:
  project: RandomUser.sln
  verbosity: detailed
  publish_nuget: true

before_build:
  - nuget restore

nuget:
  account_feed: true
  project_feed: true

deploy:
  provider: NuGet
  api_key:
    secure: oersntns349lpwtsaAThuwfs//74hanwoIEN
  skip_symbols: false
  artifact: /.*\.nupkg/&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Will let AppVeyor to take care of the release version number. For this purpose &lt;em&gt;{build}&lt;/em&gt; is used. Assembly files will be patched with the version value we define in &amp;ldquo;version&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;In order to publish to NuGet the following should be added to the appveyor.yml file&lt;/p&gt;
&lt;pre class="brush: text;"&gt;build:
  publish_nuget: true

deploy:
  provider: NuGet
  api_key:
    secure: oersntns349lpwtsaAThuwfs//74hanwoIEN
  skip_symbols: false
  artifact: /.*\.nupkg/&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You need to get your NuGet API key and encrypt it. AppVeyor offers a tool for encryption at this URL &lt;a href="https://ci.appveyor.com/tools/encrypt"&gt;https://ci.appveyor.com/tools/encrypt&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In &lt;i&gt;artifact&lt;/i&gt; you provide the file name or artifact name to push.&lt;/p&gt;
&lt;p&gt;As I said before I prefer to create NuGet packages using AppVeyor feed before pushing them for the first time to nuget.org. For this purpose you need to add the following:&lt;/p&gt;
&lt;pre class="brush: text;"&gt;nuget:
  account_feed: true
  project_feed: true&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Make sure that your project contains a &lt;i&gt;nuspec &lt;/i&gt;file in the same folder where your .csproj file is. You can find more information about &lt;i&gt;nuspec&lt;/i&gt; here: &lt;a href="http://docs.nuget.org/Create/Nuspec-Reference"&gt;http://docs.nuget.org/Create/Nuspec-Reference&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;All the tests are run automatically by the way.&lt;/p&gt;</description><pubDate>Fri, 22 May 2015 07:45:39 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/create-nuget-packages-using-appveyor</guid></item><item><title>Running xUnit.net tests using ReSharper</title><link>http://www.ralbu.com:80/running-xunit-net-tests-using-resharper</link><description>&lt;p&gt;If you have created new projects in Visual Studio recently and you use xUnit.net with ReSharper to run your tests you might find that your tests are not running. The reason for that is that xUnit.net has been updated to version 2. Also xUnit.net runner for Visual Studio is no longer needed.&lt;/p&gt;
&lt;p&gt;Follow this steps to run the new xUnit.net 2.0&lt;/p&gt;
&lt;p&gt;1. Install xUnit.net with the NuGet command&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;install-package xunit&lt;/pre&gt;
&lt;p&gt;If you check the packages.config file you&amp;rsquo;ll see that there are a few more packages added apart from xunit. One of this is the assertion library. The core framework is separated from the assertion library.&lt;/p&gt;
&lt;p&gt;2. Install xUnit Visual Studio runner&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;install-package xunit.runner.visualstudio&lt;/pre&gt;
&lt;p&gt;If you don&amp;rsquo;t use ReSharper to run unit tests this should be enough otherwise follow the next step.&lt;/p&gt;
&lt;p&gt;3. Click the &lt;em&gt;Resharper&amp;gt;Extension Manager&amp;hellip;&lt;/em&gt; Find the &lt;em&gt;xUnit.net Test Support for ReSharper 9 &lt;/em&gt;(it should be the same for 8) and click the Update button.&lt;/p&gt;</description><pubDate>Fri, 20 Mar 2015 22:23:00 GMT</pubDate><guid isPermaLink="true">http://www.ralbu.com:80/running-xunit-net-tests-using-resharper</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></channel></rss>