Team Project Rename

Renaming of Team Projects is one of the most requested feature on Visual Studio User Voice:

image

Figure 1: Team Project rename suggestion on User Voice

Today, Brian Harry announced new Visual Studio Online Update and it contains this feature, even if it will not be available to everyone at the beginning. For those people that uses TFS on-premise you will have this feature in the upcoming new version: TFS 2015.

I strongly suggests you to have a look at Visual Studio User Voice and give your suggestion, because it is in the radar of Visual Studio Team.

Gian Maria.

Professional Application Lifecycle Management With Visual Studio 2013

If you use or plan to use Team Foundation Server or Visual Studio Online, this is the book for you.

Professional Application Lifecycle Management with Visual Studio 2013 covers all aspects and tools of Microsoft ALM Ecosystem, giving you all the details on how to implement effectively ALM for your team/s. This book is dedicated to all people involved in a Software Project, from managers who plan work with new Portfolio Management features, to developers that create the product, and finally to testers and end users that could monitor quality with Microsoft Test Manager and Feedback Tool. Everything is explained clearly and with full details, making this book a perfect companion for everyday work.

Even you own previous editions, I strongly suggest you to buy this new one, because it covers all the new feature of TFS 2013. This new edition contains some brand news chapters to understand what Git offers as an alternative to TFVC for source control, as well as showing how to do Enterprise Agile with Portfolio Management or using Release management to deploy applications in production environments with a controlled and repeatable process.

Due to redesign of Team Explorer in Visual Studio 2013 and some other changes to existing features, all content of previous editions was updated and revamped to reflect latest bit of Visual Studio ALM 2013 Family.

If you use TFS or VSO is time to update your bookshelf.

Gian Maria.

Keep your Team Foundation Server upgraded to latest version

When it is time to maintain Team Foundation Server in small companies the major risk is “fear of upgrade”. In a small shops usually there is no dedicated resource to maintain TFS installation, usually you install the first time, schedule backup and everything is done. In small company maintenance is also simple, you usually have not big database and speed is not a problem with current hardware.

Some people also fear the upgrade, because they think it is a complicated process, they are not sure if they are able to restore the old version if the upgrade went wrong, and so on. First of all I suggest you to read the exceptional Upgrade Guide from TFS Rangers, it will explain almost everything you need to know about the upgrade, but I can also assure you that the upgrade process, if you are not still running an old TFS 2008, is not complex.

If you are a small company, probably all your TFS is a single machine with everything installed on it, with the only exception of build server, that usually is located in other machine.

Typical question that people ask before an upgrade are

*) What can I do if the upgrade will go wrong?

The answer is simple, first of all all data is stored inside Databases, if you have a backup all of your data is safe. If you installed TFS in a single Virtual Machine, just turn off the machine, create a snapshot, do the upgrade and if everything went bad, restore the snapshot.

*) What can I do to verify that the upgrade is really gone good?

If the procedure does not raise errors, you should try to do your everyday work, you should simply use Web Access, verify that you are able to do the automatic upgrade to process template to enable new features, use Visual Studio to access code and try to run your builds and verify that everything is ok. Remember to verify Reporting and Cube, because they are usually the most problematic area, together with SharePoint integration.

*) Can I test the upgrade while still running the old server?

The TFS Upgrade Guide has a section dedicated to how create a test upgrade environment to verify the upgrade. Basically you should be 110% sure to change id of cloned TFS to avoid confusion from Client Programs. If you have a Virtual Machine you can copy the disk and create another virtual machine with a private network, to be sure that you are

*) How much time does it takes to do the upgrade process?

This is a question that depends on so many factor. Hardware speed is the major parameter, but size of the collection is another important factor, and finally how old is your original server is another factor of speed.

My suggestion is, try to follow the update train, do not miss any update, because the most time passes between updates, the most complex the process can be. VS Team is also really committed to verify that each update work seamlessly over the last one. If you let too much time pass, it is possible that you should do a multi-step upgrade (Es TFS 2008, converted db to 2010, then to 2012 Update 4, then to 2013).

Gian Maria.

Programmatically use of Coded UI in Visual Studio

Coded UI Tests are a specific type of UI testing introduced with Visual Studio 2010. You can create your first Coded UI test following simple instruction from MSDN documentation. Most of the introductory examples shows you how you can use the Recorder tools to record interaction with a software (Web, WinForm, Wpf. etc) to generate what is called a UiMap. An UiMap is nothing more than a big Xml files where the recorder records the interaction with the UI and a bunch of automatic generated classes to interact with the UI.

Using a UiMap is probably not the best option for large projects, because the cost of maintaining it could become really high. This is usually not a big problem, because UiMap is used to generate code based on a set of classes belonging to Visual Studio Testing Framework that makes possible to interact with a UI from code. If maintaining a UiMap is difficult for you you can directly use these classes in your test. To show you the “hello world” equivalent of CUIT, here is the code needed to open a page in a browser and click an hyperlink.

using ( BrowserWindow browserWindow =
            BrowserWindow.Launch
            (
                new System.Uri("http://tailspintoys.azurewebsites.net/")
            ))
{
               
    HtmlHyperlink link = new HtmlHyperlink(browserWindow);
    link.SearchProperties.Add
        (
            HtmlHyperlink.PropertyNames.InnerText,
            "Model Airplanes"
        );
    Mouse.Click(link); 
}

The code is really simply, you must use the BrowserWindow.Launch static method to create an instance of BrowserWindow class pointing to a given Url. The BrowserWindow class is a wrapper defined Visual Studio Coded Ui assemby used to abstract the interaction with a web browser. The next step is locating the hyperlink you want to click, operation that can be accomplished with the HtmlHyperlink object. This object derives from the UiTestControl base class, and abstracts the concept of a control in the User Interface. The constructor of HtmlHyperlink object needs an instance of a containing control, in this example the whole browserWindows object. The need for the Container is having a root control that will be searched for the control.

To specify the exact Hyperlink control you want to interact with, you should populate SearchProperties collection, specifying the criteria you want to use. In this example I used the InnerText property, but you can use a lot of other criteria. Thanks to PropertyNames static collection of HtmlHyperlink object you can enumerate all the properties that can be used to locate the control. Inner Text is not usually the best option, using unique Id is usually a better approach, but the key concept is: You should use the criteria that is most stable in your scenario/environment. If you can ask to development team to assign unique id or unique names to each control, tests will be more robust and quicker.

Once SearchProperties collection is filled with critera, you can interact with the control, accessing properties or passing it to Mouse.Click method to simulate a click. CodedUI engine will locate the control on the page only when You will access properties or pass the control to some method that interact with it. This is really important, until you do not access properties the engine will not try to locate the control on the UI.

Remember to enclose the BrowserWindow object in a using block, this will ensure that the instance of the browser opened during the test will be always closed. This prevents multiple browser windows to remain opened after the test if some exception occurred.

Gian Maria.

Versioning assembly during TFS 2013 build with Powershell Scripts

One of the most important news in TFS Build 2010 is the introduction of Workflow Foundation that replaced standard MSBuild scripts used in TFS 2008. Workflow foundation can be really powerful, but indeed it is somewhat scaring and quite often customizing a build can be complex.

You can find some blog post of mine on the subject:

Years are passed, but I still see people scared when it is time to customize the build, especially because the Workflow can be a little bit intimidating. In TFS2013 the build is still managed by Workflow Foundation, but the new workflow basic template now supports simply customization with scripts.

image

Figure 1: Pre-build script configured in the build.

If you look at previous image I’ve setup a simple script to manage assembly versioning and I’ve configured it to run Before the Build, I specified version number thanks to script arguments: -assemblyVersion 1.2.0.0 -fileAssemblyVersion 1.2.J.B. The notation J and B is taken from a nice tool called Tfs Versioning; it is used to manage versioning of assembly with a Custom Action. If you ever used that tool since the beginning (Tfs 2010) you probably discovered that managing build customization with Custom Action is not so easy. Setting up Tfs Versioning tools is super easy if you simply use workflow included in the release, but if you already have a customized workflow, you need to modify the Workflow adding the Custom Activity in the right place with the right parameters.

When you move to TFS 2012 and then to 2012, you need to download the source of the tool and recompile against latest version of build assemblies, then you need to modify the workflow again. This is one of the most annoying problem of Custom Actions, you need to recompile again when you upgrade build servers to new version of TFS.

A script solution is surely more reusable, so I’ve decided to create a little script in Powershell to modify all assemblyinfo.cs files before the build. I’m not a Powershell expert and my solution is not surely optimal, but is a simple proof of concept on how simple is to accomplish build versioning with a script instead of direct customization of the workflow with custom actions.

To have reusable code I’ve create a script called BuildFunctions.psm1 that contains all functions that can be useful during the build. Here it is the function that takes care of versioning for C# projects.

function Update-SourceVersion
{
  Param 
  (
    [string]$SrcPath,
    [string]$assemblyVersion, 
    [string]$fileAssemblyVersion
  )
    
    $buildNumber = $env:TF_BUILD_BUILDNUMBER
    if ($buildNumber -eq $null)
    {
        $buildIncrementalNumber = 0
    }
    else
    {
        $splitted = $buildNumber.Split('.')
        $buildIncrementalNumber = $splitted[$splitted.Length - 1]
    }

    if ($fileAssemblyVersion -eq "")
    {
        $fileAssemblyVersion = $assemblyVersion
    }
    
    Write-Host "Executing Update-SourceVersion in path $SrcPath, Version is $assemblyVersion and File Version is $fileAssemblyVersion"
 

    $AllVersionFiles = Get-ChildItem $SrcPath AssemblyInfo.cs -recurse

    
    $jdate = Get-JulianDate
    $assemblyVersion = $assemblyVersion.Replace("J", $jdate).Replace("B", $buildIncrementalNumber)
    $fileAssemblyVersion = $fileAssemblyVersion.Replace("J", $jdate).Replace("B", $buildIncrementalNumber)
    
    Write-Host "Transformed Version is $assemblyVersion and Transformed File Version is $fileAssemblyVersion"
 

    foreach ($file in $AllVersionFiles) 
    { 
        Write-Host "Modifying file " + $file.FullName
        #save the file for restore
        $backFile = $file.FullName + "._ORI"
        $tempFile = $file.FullName + ".tmp"
        Copy-Item $file.FullName $backFile
        #now load all content of the original file and rewrite modified to the same file
        Get-Content $file.FullName |
        %{$_ -replace 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', "AssemblyVersion(""$assemblyVersion"")" } |
        %{$_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', "AssemblyFileVersion(""$fileAssemblyVersion"")" }  > $tempFile
        Move-Item $tempFile $file.FullName -force
    }
 
}

If you are a powershell expert, please do not shoot the pianist :), this is my very first serious Powershell script. The cool part is that Build Subsystem stores some interesting values in Environment Variables, so I can simply found the actual build number with the code: $buildNumber = $env:TF_BUILD_BUILDNUMBER. The rest of the script is simply string and Date manipulation and a RegularExpression to replace AssemblyVersion and AssemblyFileVersion in original version of the file, you can find details Here in the original post I’ve used as a sample for my version.

The cool part about this script is that you can import it in another script to use functions decalred in it. The goal is maintaining all complexities inside this base script and use these functions in real scripts that gets called by TFS Build. This simplify maintenance, because you only need to maintain function only once.  As an example this is the simple PreBuild script that manages assembly numbering.

 Param
(
[string] $assemblyVersion,
[string] $fileAssemblyVersion
)


Write-Host "Running Pre Build Scripts"

$scriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition

Import-Module $scriptRoot\BuildFunctions

if ($assemblyVersion -eq "")
{
    $assemblyVersion = "2.3.0.0"
    $fileAssemblyVersion = "2.3.J.B"
}
 

Thanks to Import-Module commandlet I can import all functions of file BuildFunctions.psm1. This is much more simpler than having Custom Actions and insert them inside the workflow.

One of the coolest part of Powershell scripts is the ability to define parameters in the head of the script so you can specify them with notation –parameter value leaving all the parsing burden of commandline to Powershell infrastructure. Another cool part of this approach is that you can include a base AssemblyVersion number to be used if no valid number is passed by Command Line. Thanks to Git Support you can create a simple build definition valid for multiple branches and in such scenario it is much better to have version number stored in source control, because you can specify a different build number for each branch.

Now just fire a build and verify that assemblies in drop folder contains correct numbering.

image

Figure 2: Verify that all the assemblies contains the correct AssemblyVersionFile Number

If something went wrong, you can look at the diagnostic of the build to verify what is happened in the script. All Write-Host directive are in fact intercepted and are collected inside the diagnostics of the build.

image

Figure 3: Output of the scripts is collected inside the Diagnostic of the build.

Thanks to this approach you can

  • Create a simple reusable set of functions inside a Powershell Base Script
  • Use functions contained in Powershell Base Script inside simpler script for each build
  • All Write-Host output is redirected in diagnostic log of the build to diagnose problem.
  • Customization is still valid if you upgrade TFS
  • You can customize the build simply specifying path of the script.
  • You can test the script running it locally

If you compare how simple is this approach compared to managing customization of Workflow with Custom Action you can understand what a great improvement you got using the new TFS Build templates.

Gian Maria.