Category Archives: Uncategorized

Custom Activities build process

If you are like me and you create a number of Custom Build Activities for TFS you want to ensure that you keep them in a tidy place.

The best place I have found is to find the BuildProcessTemplates folder and add a new folder called CustomActivities, and in this folder place all your xaml and dll’s files that you have created.

Once you’ve created the new folders and files you’ll need to make sure the build controller know about them, click Build > Manage Build Controllers then select the properties and enter :


under the Version control path to custom assemblies.













Enhancing the Build in TFS 2012

TFS has the ability to run automatic builds on the build server, this ensures that your project and solutions build and all their dependencies are near by and functional. I’ve looked all over the internet and found various samples, but none that work with Visual Studio 2012 or in the way I wanted the versioning to work. In this post I pulled together everything I have found whist looking over the Internet, I have tried to keep the same process and names as many of the samples I have found while searching for the solution.

So what we want to do is to change the standard build process to enable us to do automatic versioning of assemblies.  To do this what we need to do is insert some steps in the process just after the source has been retrieved from TFS.  We want the workflow that goes something like this:

Get Latest –> Update AssemblyInfo files with new version –> Build the solution

We need to remember that that when team build gets the code from TFS the files are in read only mode, so we’re need to change the read only flag off, change the files, and then turn it back on.  

What we are not going to do is check the updated assembly info files back into source control.  This means all developer builds will by default have a version number of and build server builds will have an incrementing build number.  This is a useful way to know if someone has tried to deploy code built on their machine instead of code built by the server.

The version number will take the format of 

Major build (Application major version)

Minor release (Application minor release)

Date (month day) (Date of the build)

Incrementing build number (This number will change on every build)

We should end up with a format looking something like this:


Building the solution

Why do we need a solution, several reasons, we need to be able to build our custom assembly and more importantly we need to be able to edit, change the custom workflow template and then have the ability to compile the workflow to ensure it is built correctly.

1.  Open VS2012 and create a solution with two C# Class LIbrary projects in it.  One for the custom build tasks we’re going to create, and one to hold the process template we’re going to change.  I have called it CustomBuildActivities and CustomBuildProcess, I’ve opted for both standard Class Libraries, as I wanted to go over what references we need to add in order to build our workflow.









2,  Now go copy the DefaultTemplate.xaml file, which you should find in the Source Control Explorer under the BuildProcessTemplates folder, rename it to something you like and include it in your project.  I have called it ExtendedBuildProcess.xaml.  Once it’s included in the solution change the Build Action to XamlAppDef. 












At this point if you try compiling you’ll get a lot of missing references.

  • System.Activities
  • System.Xaml
  • System.Activities.Presentation
  • PresentationFramework
  • WindowsBase
  • System.Drawing
  • Microsoft.TeamFoundation.Common
  • Microsoft.TeamFoundation.Build.Client
  • Microsoft.TeamFoundation.VersionControl.Client
  • Microsoft.TeamFoundation.VersionControl.Common
  • Microsoft.TeamFoundation.WorkItemTracking.Client
  • %Program Files%\Microsoft Visual Studio 11.0\Common7\IDE\ReferenceAssemblies\v2.0\
  • %Program Files%\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\
  • %WinDir%\assembly\GAC_MSIL\Microsoft.TeamFoundation.TestImpact.Client\\

Quite a lot I know, but I wanted to take you though everything that is needed.

Creating our Custom Activity

The first custom activity we are going to build will be the one we use to toggles the read only flags on AssemblyInfo files.  In your CustomBuildActivities project add a new Class called SetReadOnlyFlag.  We’ll use this to toggle the read only bits for our AssemblyInfo files later on.

We’ll need to add a few references first

  • System.Activities
  • Microsoft.TeamFoundation.Build.Client
  • Microsoft.TeamFoundation.VersionControl.Client
  • System.IO


using System.Activities;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using System.IO;
namespace CustomBuildActivities
 public sealed class SetReadOnlyFlag : CodeActivity
  public InArgument<string> FileMask { get; set; }
  public InArgument<bool> ReadOnlyFlagValue { get; set; }
  public InArgument<Workspace> Workspace { get; set; }
  protected override void Execute(CodeActivityContext context)
   var fileMask = context.GetValue(FileMask);
   var workspace = context.GetValue(Workspace);
   var readOnlyFlagValue = context.GetValue(ReadOnlyFlagValue);
   foreach (var folder in workspace.Folders)
    foreach (var file in Directory.GetFiles(folder.LocalItem, fileMask, SearchOption.AllDirectories))
     var attributes = File.GetAttributes(file);
     if (readOnlyFlagValue)
      File.SetAttributes(file, attributes | FileAttributes.ReadOnly);
      File.SetAttributes(file,attributes & ~FileAttributes.ReadOnly);

This is the first Custom Activity done

Update Assembly VersionInfo Custom Activity

This Custom Activity is to change all the Version numbers to the format we are after, e.g.  3.1.1207.32454

using System;
using System.Activities;
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.TeamFoundation.Build.Client;

namespace CustomBuildActivities
    public sealed class UpdateAssemblyVersionInfo : CodeActivity
        public InArgument<string> AssemblyInfoFileMask { get; set; }

        public InArgument<string> SourcesDirectory { get; set; }

        public InArgument<int> Major { get; set; }

        public InArgument<int> Minor { get; set; }

        protected override void Execute(CodeActivityContext context)
            var sourcesDirectory = context.GetValue(SourcesDirectory);
            var major = context.GetValue(Major);
            var minor = context.GetValue(Minor);
            var assemblyInfoFileMask = context.GetValue(AssemblyInfoFileMask);
            var buildDate = int.Parse(string.Format("{0}{1}", DateTime.Now.Month, DateTime.Now.Day));
            var newVersion = new Version(major, minor, buildDate);

            foreach (var file in Directory.EnumerateFiles(sourcesDirectory, assemblyInfoFileMask, SearchOption.AllDirectories))
                var text = File.ReadAllText(file);
                // we want to find 'AssemblyVersion("")' etc
                foreach (var attribute in new[] { "AssemblyVersion", "AssemblyFileVersion" })
                    var regex = new Regex(attribute + @"\(""\d+\.\d+\.\d+\.\d+""\)");
                    var match = regex.Match(text);
                    if (match.Success) text = regex.Replace(text, attribute + "(\"" + newVersion + "\")");

Okay that is the coding done, your project should build without and errors, warnings or message, perfect and clean project.

Now the fun really starts

Updating the Extended Build Process Workflow

Before we start can you make sure the project builds without an errors.





When you open your ExtendedBuildProcess.xaml on the toolbar you should find the two new CustomBuildActivites (SetReadOnlyFlag and UpdateAssemblyVersionInfo)

Now comes the tricky bit finding in the workflow where to drop the Custom Activities.  You can search the Workflow manually or use the Find option and look for “Get Workspace”, you should end up in the section of the work flow that looks something like this:












Now add a sequence activity after the get workspace activity:







Now add your two new Custom Activities to the Sequence activity, with the SetReadOnlyFlag going either side of the UpdateAssemblyVersionInfo.









Set Activity Properties

For each of the new Customer Activities we are going to have to set the required parameters






Select the Readonly Activity and then look at the properties






Before we set the properties we’ll need to set the Arguments that are coming in to the Workflow, so go to the Arguments tab at the bottom of the workflow.





Click in the Create Argument box and add a new argument called AssemblyInfoMask and give it a default value of “AssemblyInfo.*”

Create a further two arguments AssemblyMajor and AssemblyMinor setting them both to Int32 with 1 and 2 default values.


You don’t have to do this process, next but when you do it will appear in the Build process in the correct section.  Go to the metadata argument a few lines above and click the ellipsis […] button.  You will see a window appear where we can set values that will let Visual Studio know how to display this argument to the end user.  Do this for all three arguments. 












Okay now we have set the argument we can set the properties of the Activity.
















Okay that should be it.  So build the solution just to make sure everything is DONE!

Next just follow the steps to store your new custom activities and then add them in to your build process and you’re done.

I would not have been able to complete and understand this process without the help of the following two web pages. 

Customize Team Build 2010 by Ewald Hofman

How To: Versioning Builds With TFS 2010 by Richard Banks

Deploy website from Visual Studio to IIS

MSDeploy is really good for deploying websites and syncing up websites but it can be a real pain to configure and get going intially. The MSDeploy documentation is a bit poor as well and quite often you’ll get a very strange error which can be quite cryptic.


The error message isn’t actually too bad in this case, it’s saying either the Web Management Service isn’t running OR it can’t find MSDeploy. Ok so checklist for this problem:

  • Web Management Service (WMSVC) is running on the target server
  • Port 8172 is open (checked with Telnet for good measure)
  • Can you connect to https://servername:8172/msdeploy.axd
  • Is MSDeploy installed
installing the latest version ms MSDeploy did it for me. 
For a full Microsoft answer check out Configuring a Web Server for Web Deploy Publishing (Web Deploy Handler)
If you are still having troubles go though this set of steps: 

VS12 switching Menu to Lowercase

If you are like me and you don’t like people shouting, you’ll be quite releaved that you can stop the Menus from Visual Studio 2012 from shouting at you by changing the Menus from Uppercase to Lowercase is as simple as adding the following key in the registry:

REG_DWORD value: 1

iOS 6 Passbook problem

So you’ve upgraded to iOS 6 and keen to tryout all the new features one of them being the Passbook, time to get rid of all those printed tickets and even start thinking of replacing that old leather wallet.

So you click on the Passbook





Then you tap the App Store button to see what apps that are supported with Passbook.











If you are like me you’ll get “Can’t connect to iTunes Store” error  Undecided

But wayhay I found the old solution of setting the date forward manually cure this issue.  It takes a few easy steps to manually change the date.

  • Open Settings
  • Open General
  • Open Date & Time
  • Turn off Automatically setting to Off
  • Open Set Date & Time
  • set the date to one year ahead
Now try out the Passbook and you’ll be able to connect to the Apps Store, if you are like me you’ll be disappointed as only two apps are currently available United Airlines and Lufthansa, none of which I use or have any intention of using.
Oh don’t forget to reset your Date to Automatic


SQL Server Broker

I’ve been playing with SQL Server Broker services to allow me to notify my C# code when some data has been changed, but first you need to enable SSB (SQL Server Broker).  The easiest way of doing this is to us the following SQL statement:

alter database [<dbname>] set enable_broker with rollback immediate;

The reason for using rollback immediate is that the statement needs to have exclusive access to the database, and any connection has a shared lock on it, even when idle.

MEF with MS Workflow

I’ve been a strong advocator of MEF for some time now, and with some of my work is now based around MS Workflow I thought it would be a good time to get MEF working with MS Workflow.

Before we start we need to know a few things:

  1. MS Workflow does not have a normals constructor
  2. When will we import our objects

Two simple tasks for any normal project, but MS Workflow is different, as we all know.

So to start with to deal with te fact that MS Workflow does not have any constructors we can use Extensions, as these are fired up when MS Workflow is started up.  To do this it is simpley a task to add the extension in to the web.config file under <extensions> tag

        <add name="mefProviderExtension" type="MEFExtension.WorkflowServiceBehaviorElement, MEFExtension"/>

The code by default picks up the Exported MEF objects from the BIN folder and a bin/PlugIns folder, however you can have a test in bin/tests folder, to do this you can add to behavioura mefProviderExtension

<mefProviderExtension  useTestServices="true"/>

Then with every CodeActivity use the MEF method of SatisfyImportOnce to inject the MEF objects.


I have taken the code written by Gareth Berlow from CodePlex called MEF and Workflow Services Integration and adapted the code to make it easier to use, simply but moving all the MEF code in to a MEFExtension but still allowing the ability to generate your own overrides of the MEF object if required.

MSWorkflow (66.04 kb)

JSFiddle, lovely online tool for trying out your javaScript

I wanted to have a play with jQuery AutoComplete, so like many people I found the source and created a HTML page locally on my machine.  Then you test it out, save it, uploaded it, or email it to where you need it.

Well no more jsFiddle is a playground for such trivial tasks, you can build HTML, CSS and JavaScript all online.  It even allows you to choose a Framework (such a jQuery) and different versions.

So this was my first attempt at using the jQuery AutoComplete

Assigning SSL certificate in IIS 6

If when in a test invironment you need to test out SSL (HTTPS) on your website you can create a self-assigning SSL certificate (this process only appiles to IIS6)

Typically, Secure Socket Layer (SSL) Certificates are created for domains by first generating a Certificate Signing Request (CSR) through Internet Information Services (IIS), sending the request to a known Certification Authority, such as GeoTrust, which generates a corresponding Certificate file for use in conjunction with the CSR, completing the request and securing communications on the domain.

However, IIS does come with the ability to create a ‘self-signed’ certificate, in which the server generating the CSR also generates the corresponding Certificate file. These are mainly used for testing, development and troubleshooting, as the certificate will only be recognized as valid by the server it is hosted on. Attempting to view the secured domain externally would receive an error that the certificate is not valid, as it has not been approved nor is recognized by a known Certification Authority.

To create a self-signed SSL certificate for any hosted domain on your server, you will first need to download and install the SSL Diagnostics Kit v1.1, which can be obtained free of charge from Microsoft via the following URL:

SSL Diagnostics Version 1.1 (x86)SSLDiag.msi (532.00 kb)

Given the option to either Run or Save the file, choose ‘Save’.

For now, let’s save the file to the desktop. Click ‘Save’ again.

Once the download is complete, double-click the icon to begin the installation.

Click ‘Next’ on the initial window.

Enter your desired Name and Company information, and click ‘Next’.

The next screen will provide options for which type of installation you prefer. You can click ‘Complete’ to install the Diagnostics.

You are now ready to install the diagnostics. Click ‘Install’.

When the installer confirms it has completed, click ‘Finish’.

Now, we need to get some information from IIS before we can generate the self-signed certificate. Open IIS by navigating to ‘Start –> Administrative Tools –> Internet Information Services (IIS) Manager’.

Once IIS is open, expand the Server Name, then click on the ‘Web Sites’ folder. This will bring up a list of all web sites on the server in the right-hand pane. You will notice that each site has a unique number assigned to it under the ‘Identifier’ column. This is the number which we need in order to create the self-signed certificate. As you can see, the Identifier for ‘’ is 957.

Next, we need to open a DOS Prompt. You can do this by navigating to ‘Start –> Run’, typing ‘CMD’, and clicking OK.

Once the DOS prompt is open, we will need to navigate to the directory where the SSL Diagnostic Toolkit is located. This directory is ‘C:\Program Files\IIS Resources\SSLDiag’. To navigate to this directory, at the DOS prompt, enter the following command:

cd C:\Program Files\IIS Resources\SSLDiag

The ‘cd’ command stands for Change Directory. Press Enter once the command is typed in, and the prompt will bring you right to the directory, as seen below.

Now, we need to enter the command which will actually create the certificate. The base command to create the certificate is ‘ssldiag /selfssl’, however command requires certain parameters for the certificate to be successfully created. These parameters are as follows:

    /N: – This specifies the common name of the certificate. The computer name is used if there is no common name specified.
    /K: – This specifies the key length of the certificate. The default is length 1024.
    /V: – This specifies the amount of time the certificate will be valid for, calculated in days. The default setting is seven days.
    /S: – This specifies the Identifier of the site, which we obtained earlier. The default will always be 1, which is the Default Web Site in IIS.

Let’s use the following command to create a self-signed certificate for ‘’ (you’ll need to ensure that the DNS server has this domain name pointing to your IIS machine) which is valid for two years, using a common name of ‘’, a key length of 1024:

ssldiag /selfssl / /K:1024 /V:730 /S:957

Once you have set the parameters to your preference, enter the command into the DOS prompt, and press Enter. After pressing Enter, the DOS prompt will simply move to the next line.

Now, we can check IIS and verify the certificate is now in place. Using the steps outlined above, navigate back to IIS, right-click on the domain, and choose ‘Properties’.

Inside the Properties window, click on the ‘Directory Security’ tab.

On the Directory Security tab, under the ‘Secure Communications’ heading, click on the ‘View Certificate’ button, as it is now enabled.

This windows confirms the certificate has been successfully installed. Note the ‘Issued By’ field, as typically the issuer would be a known Certification Authority, such as GeoTrust, however here the issuer is ‘’. This confirms the certificate is self-signed. Click OK to close the window.

You can now view the site on the server under a secure heading. Again, please note that as the certificate is self-signed, and does not have a matching Root Certificate from a Certification Authority, attempting to view the site under a secure heading from an external location will cause a certificate error. Self-signed certificates should only be used for testing and development, and under no circumstances should be substituted for a CA-approved SSL Certificate for a live, production website.

This has been extracted from ServiceFirst Support