But it works on my PC!

The random thoughts of Richard Fennell on technology and software development

Professional Foundation Server 2010

Over the holiday I have been reading Professional Foundation Server 2010 by Ed Blankenship, Martin Woodward, Grant Holiday and Brian Keller, yes I know how to have time off and have fun!

So who is this book for? It is a comprehensive guide to TFS 2010, the components and their usage, but this does not mean the book is only for teams new to TFS or people planning to take certification exams. Spread throughout there are useful little titbits of information where you find yourself going ‘I never know that’ or ‘arr.. that explains so much

image

So I would suggest it is well worth a look for anyone who is working, or planning to work, with TFS.

It is even available as Kindle edition, how times change, used to be only novels for the Kindle!

How to use the TFS 2010 Community StyleCop Build Activity

[Updated 27th April 2011 Also see How to use the TFS 2010 Community StyleCop Build Actvity (Addendum)]

The Codeplex Community TFS Build Extensions contains a StyleCop activity, but the way to use it is less than obvious. This is not helped by the complexity in using any custom activity within TFS 2010 builds. In this post I will try to show how to get going with the StyleCop activity, which might shed some light on using other custom assemblies.

Get the files

  1. Download and install StyleCop on you development PC. The alpha 1.0.0.3 custom activity is built against StyleCop 4.4.0.14.
  2. Download and unzip the Community TFS Build Extensions to a directory on you development PC.

Get the files onto the build box

The assemblies that contain the custom activity and StyleCop need to put under source control so they are available to the build controller and agent(s).

  1. In VS2010 open Source Control Explorer select your Team Project and map the BuildProcessTemplates folder to a location on your local disk.
  2. Create a new folder under the BuildProcessTemplates called Custom Assemblies
  3. In this new folder copy all the assemblies from the unzipped TFS Build Extensions and StyleCop folder (found in Program Files)
  4. From within Source Control Explorer add these new files to the new Custom Assemblies folder and check the files into TFS.
  5. Open Team Explorer, right-click on Builds and select Manage Build Controllers
  6. Select the controller to configure, and then select Properties
  7. Set the Version control path to custom assemblies to the location just created under version control containing your added assemblies

Get the custom activities into Visual Studio

Next we need to get the activity into Visual Studio so we can add it to build process

  1. Open Visual Studio 2010
  2. Create new Class Library project, this new project is only going to be used as a container for the editing of the build process template.
  3. Delete the Class1.cs file
  4. In Solution Explorer right click and select Properties., make sure the new project does not build in any configuration.

Now we have a project to work with, we need to get a process template into it, this can be done by branch the process template into the project for adding it as a link. In this example I used a link to one of the standard template in the BuildProcessTemplates folder, for simplicity, but I would normally recommend at least copying the process template in the BuildProcessTemplates folder prior to editing it.

  1. Make sure BuildProcessTemplates is mapped in you current workspace and get a local copy on your development PC
  2. In the new project select Add Existing Item and browse to local folder mapped to the BuildProcessTemplates, select the template your wish to edit. But, don’t just press the Add button, but use the drop down to select Add as link.
  3. On the added file set the build action property to none
  4. Select Add Reference and add references to all the assemblies from the unzipped TFS Build Extensions
  5. Open the newly added process template in VS2010, this can be slow, so wait…..
  6. Open the toolbox and you should see all the standard build activities
  7. Right click in the toolbox and select Choose Item, select browse and select the file TfsBuildExtensions.Activities.StyleCop.dll.
  8. The StyleCop activity should now be in the toolbox

Editing the Process template

Well at last we can start to edit the process template, that took a while didn’t it!

Using the standard DefaultBuild template find the ‘Compile the Project’ sequence and add the activities as show in a graphic below. I have chosen to add the sequence inside the compile the project so we can pickup the solution file’s location, but you could choose a different location of that meets you needs. The StyleCop activity does not require to be after the compile stage as it works against the .CS files, not the compiled assemblies.

image

Here are the breakdown

  1. Add a new sequence, I named it “Run StyleCop”
  2. Add the following variable with a scope of the “Run StyleCop” sequence
    • StyleCopFiles – iEmumerable<string>
    • StyleCopSettingsFile – string
    • StyleCopResults – bool
    • StyleCopViolations - int32
  3. Add a FindMatchingFile activity, set the result to StyleCopFiles and the MatchPattern to String.Format("{0}\**\*.cs", BuildDirectory). This will recursively find all the .CS files in the project and add them to the collection.
  4. Add an Assign activity, set the to property to StyleCopSettingsFile and the value to String.Format("{0}\Settings.StyleCop", localProject.Substring(0, localProject.LastIndexOf("\"))). We use the name of the .SLN file to find the root folder to find the StyleCop settings file.
  5. Add a WriteBuildMessage activity, set the importance to High (so we always see the message) and the Message to String.Format("About to run Stylecop with {0}", StyleCopSettingsFile)
  6. Add a StyleCop activity with the following properties (these are a minimum to get it working, to see what the other options do I would suggest you look at the unit tests in the Codeplex activities source.)
    • SettingsFile = StyleCopSettingsFile
    • SourceFiles = StyleCopFiles.ToArray()
    • Succeeded = StyleCopResults
    • TreatViolationsErrorASWarnings = True  - setting this is down to how you want violations to appear in the log, for this example I wanted warnings
    • ViolationCount = StyleCopViolations
  7. Add another WriteBuildMessage activity, again set the importance to High and the Message to String.Format("StyleCop Successed:{0} with {1} violations", StyleCopResults, StyleCopViolations)
  8. Save the edited process template and check it into TFS

Running the Build

If you have not done so already create a build using this process template. Queue a new build using the template. If it is all OK you should see a log similar to the graphic below

image

Notice that the FXCop (code analysis) results appear within the main build summary (green), but the StyleCop violations (red) appear in the Other Errors and Warnings section. Unfortunate this cannot be altered. You cannot add extra bits to the main build summary. However, you could choose to fail the build if there are StyleCop violations

So I hope this has made the use of the StylCop activity more obvious, so you can bolt it into your build process and trigger all the argument in your team as to which rules should be used.

Now I have three TFS build instances on my VM

A while ago I posted on my experiences running multiple instances of 2010 build service on a single VM. Well a couple more experiences as now one of my VM is running 3 instances.

Firstly it seems to work OK, you have to have the right build profile i.e. fairly low load but a need to support many Team Project Collections. This is not a solution for a highly loaded build environment. At Black Marble we run a TPC per client model and tend to have fair few projects on the go at any one time, so need plenty of build controllers. However, in general the builds are small, taking minutes not hours If we have a seriously long running build I would still create a dedicated build service VM.

So what have I learn since the last post

  • Set the agents working directory differently for each agent on the VM. You will probably be OK if you don’t, as the $(BuildAgenId) should differ, but life is easier of you know what is where. So I use $(SystemDrive\Build1, $(SystemDrive\Build2 etc. as opposed to the default $(SystemDrive\Build.

image

  • When you create the new service instance using the Sc.exe command line remember to make sure it starts automatically when the operating system is rebooted. Stupid mistake but I keep make it!

Release of Black Marble’s WP7 TFS Phone Explorer

Over the weekend we have released Black Marble’s WP7 TFS Phone client to the WP7 Marketplace.

smallpanoramaWPhone

This app allows the user of a WP7 phone to access their TFS server to perform common operations. They can:

  • See recent builds and drill into the results
  • Queue new builds
  • View and add work items

This client talks via a custom web service to a TFS 2008 or 2010 server, which are available from Black Marble. But if you just want a quick look to see what it can do we have setup a demo web service so you can trial the application, just use the default account details stored in the application. These are 

  • UID demo
  • PWD demo
  • DOMAIN demo
  • URL https://tfssample.blackmarble.co.uk/tfs/tfs/tfsservice.svc

So if you have WP7 and TFS why not download the trial version and have a look at it? Just search the market place for Black Marble and TFS Phone Explorer or try the marketplace deep link. We are interested to hear your thoughts

TF30162: Task &quot;UploadStructure&quot; from Group &quot;Classification&quot; failed

When trying to create a new Team Project on TFS2010 from a client PC I got the following error

Event Description: TF30162: Task "UploadStructure" from Group "Classification" failed
Exception Type: Microsoft.TeamFoundation.Client.PcwException

Inner Exception Details:

Exception Message: TF205029: No catalog resource type exists with the following identifier: 41c8b6db-39ec-49db-9db8-0760e836bfbe. (type CatalogResourceTypeDoesNotExistException)

However if I did the create on the TFS console all was fine.

Turned out the problem was due to the caching done by Team Explorer in Visual Studio. Exiting the copy of VS2010 on the client and reloading it fixed the problem as the updated team process settings will cached locally.

TF255115 Access Denied when starting TFSAgent Service

Whist configuring a new TFS2010 server I got the error

TF255115: The following service did not start: TfsJobAgent. Cannot start service TfsJobAgent on computer '<COMPUTERNAME>'.

This was identical to the thread on MSDN and it turned out my problem was similar.

I was installing TFS onto drive D:\APPS, not the usual C:\PROGRAM FILE. The problem was the <COMPUTERNAME>\User group did not have the default Read & Execute, List Folder Contents and Read rights on the D:\APPS directory and sub directory, the right all users have on C:\PROGRAM FILES.

Once these rights were added the TFS configuration completed without issue.

By the way something else I noticed, you can only change the path TFS will install on if you set the check boxes to install all components (server, proxy build etc.) However, once the path is altered you can deselect any components you don’t want, at which point the path textbox become read only again, but you now have the path you wanted

New home for my Techdays video on Lab Management from last year

Last year I presented at Microsoft UK’s Techdays on Visual Studio 2010 Lab Management and the session was videoed. I recently tried to refer someone to this recording and I found that the Techdays site had been rebuilt for this years event and I could not find the video. Well after a bit of searching I found it on MSN at Putting some Testing into your TFS Build Process

Why can’t I see my TFS reports?

Whist recently installing a TFS 2010 system onto a single box server, that was also a domain controller, I had a problem that though everything seemed in order I could not view my reporting services based reports in either SharePoint or directly from the http://myserver/reports interface.

During the installation I had verified I had the correct password for my [domain]\tfsreports account used to run the reports. If went to the http://myserver/reports page and edited the TFS2010ReportsDs or TFS2010OlapReportDS and tried to test the [domain]\tfsreports login it failed. However, if I swapped to the [domain]\administrator all was fine and my reports worked.

So what was the issue?

The key point is that the server, as it is a PDC, would only allow limited accounts to login to the server console. The actual Reporting Services web services were running as a named domain account (you cannot use Network Service and like on a PDC), but it seems that the connection by the [domain]\tfsreports account is considered the same as a login via the login screen as far as security systems are concerned.

The immediate fix was to make sure the [domain]\tfsreports user was in a group listed in the “Allow log on locally". To check this

  1. Run gpedit.msc
  2. Expand Computer Configuration\Windows Settings\Security Settings\Local Policies
  3. Click on User Rights Assignment
  4. Ensure that "Allow log on locally" includes user required, or that the user is in one of the listed groups

Now I am not sure this is the end of story, I am sure I can waste loads of time to find out exactly the minimum security settings needed, but this is an adequate solution for no for me.

How to waste time with Lab Management – Missing the obvious that MTM points to a Team Project

I posted a while ago about common confusion I had seen with Lab Management. We I have recently managed to get myself completely confused whilst working with Lab Management. It turns out the issue was so obvious I managed to miss it for hours, but as usual I learnt a good deal whilst trying to troubleshoot my stupidity.

I have a Lab Management system linked up to a a Team Project Collection (TPC). In this TPC there is a Team Project used for SharePoint development and on my Lab Management system I have an environment to allow testing of the SharePoint products. I setup a new Team Project in this TPC. In the new project I created a new MVC solution and created an automated build, which all worked fine.

I wanted to deploy this MVC application to a web server in an environment in my Lab Management system. So I created a basic web server environment and deployed it onto a host in my Lab. I then tried to create a Lab Management workflow build to deploy to the newly created environment. However the combo to select the environment was empty when I ran the wizard.

image

I was confused, I knew I had an environment on the Lab Management system, I had just created it in Test Manager (MTM) I could attach to it in MTM or Remote Desktop.

So I checked again

  • that the TPC was correctly registered with Lab Management
  • the environment was running in MTM
  • that all the configuration for the Team Project looked OK via TFSLABCONFIG.EXE

All to no avail. Then after far too long I realised I was not looking at the same things in MTM and Visual Studio.

When you are in the Lab Center (green border) pages of MTM there is no obvious indication of the Team Project you are using. I had forgotten this and got it into my head I was looking at all the environments and libraries for my whole TPC. THIS IS NOT THE CASE. The environments and libraries are Team Project specific and not TPC specific. I had created my new environment in my SharePoint team project not in my new MVC one.

To swap Team Project I needed to change to the Testing Centre (blue border) view and change the Test Plan (top right)

image

to get the dialog to change the Team Project.

image

Once this is done you can go to the Lab Center again and you see the environments for the selected Team Project. This was where I needed to create my environment.

At this point you will notice that all the templates and VMs you imported into the other Team project are not in this one. You have to reimport them from SCVMM and then create the environments in MTM for that Team Project

To the technical tip here is remember that Lab Center in MTM is Team Project specific – NOT Team Project Collection specific, but it does its best to not remind you of this fact so it is easy to forget.