Convert a Class Library to a Test Project in Visual Studio

Occasionally, you may run into a Visual Studio Class Library project that contains unit tests. This can be a frustrating scenario because creating a unit test using Visual Studio’s right-click context menus will not allow you to add a test to the project.

This can be remedied quite easily, though, by adding the correct project type guid to the Class Library’s project file. Here are the steps to do this from within Visual Studio:

  1. Right-click the project in Solution Explorer and choose Edit Project File
  2. Add a new child in the <PropertyGroup> node:
  3. Save your changes and close the file
  4. Right-click the project in Solution Explorer and choose Reload Project

After following those steps, your project will show in the list of output projects in the Create Unit Tests dialog box.

For a list of known project type Guids, check out this site:

TFS SDK: Getting Started

TFS is great, but it simply doesn’t do everything I need it to do. My team has a TFS work-item-driven software development life-cycle that depends on having stories organized with tasks of certain activity types performed in a specific order. It’s a difficult process for new team members to internalize, and it requires discipline for even our veteran team members. One of the things that I’ve decided to do to help my team manage this process successfully is to create a custom tool with built in “queues” that will display their work items as they need attention without relying on the developer to manually run different queries and discover items on their own.

And so that brings us to the TFS SDK. I’m going write a series of short posts detailing how to do some simple tasks that can be combined to do very powerful things. One of the simplest and most powerful things you can do with the TFS SDK is run WIQL queries to query work items using a SQL-like syntax.

The first step you need to do is simply to add the TFS SDK references to your project. These are the three I added to my project:


Once you’ve got that, you can build an execute a query with the following block of code:

var tpc = new TfsTeamProjectCollection(new Uri("http://YourTfsServer:8080/tfs/YourCollection"));
var workItemStore = tpc.GetService(); 
var queryResults = workItemStore.Query(@"
    SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] 
    FROM WorkItems 
    WHERE [System.AssignedTo] = @me 
    ORDER BY [System.Id]
foreach (WorkItem wi in queryResults)
    Console.WriteLine("{0} | {1}", wi.Fields["State"].Value, wi.Fields["Title"].Value);

Bonus tip: you can construct your WIQL query by building it from Visual Studio’s Team Explorer and saving it to file. For my application, I’m storing the WIQL query in my app.config to allow for quick & easy customization.

Undoing Pending Changes from Another User in TFS

From time to time, we run into a situation where a team member leaves or becomes unavailable, but they still have files checked out in TFS. This can be troublesome if they have an exclusive lock on a file, or it can be a housekeeping issue if they have a lot of files checked out everywhere.

If you have rights, there is a relatively simple way to undo changes from another user to clean-up a bit.

First, you need to know the name of the user’s workspace(s). You can do this by running the following command:

tf workspaces /owner:"username" /server:http://tfsserver:8080/collection

Then, to undo all pending changes from a particular workspace, run this command:

tf undo /workspace:"WORKSPACE;username" /server:http://tfsserver:8080/collection /recursive "$/teamproject"

If successful, you should receive a message like this:

The operation completed successfully.  Because the workspace xxxx;xxxxxxxx is not on this computer, you must perform a separate get operation in that workspace to update it with the changes that have been made on the server.

Reference: here.

Private Builds in TFS

My team has configured TFS to automatically kick-off continuous integration (CI) builds when developers check-in changes. The build depends on the affected area, and the time to complete depends on the build. Some of our builds contains hundreds of projects and thousands of unit tests, and these can take the better part of an hour to complete. We also have nightly builds that build even more and take even longer.

Occasionally, I’ll have some changes to check-in at the end of the day. I check them in, and I get a notification that I broke the build when I’m halfway home. Crap. I need to fix the change before the nightly build starts, or it’s going to break, too.

Wouldn’t it be great if there was a way to run a build with my pending changes and then check them in automatically if the build succeeds? Well… There is! TFS has support for private builds (or “buddy builds”) that you can queue with a shelveset.

When I choose to queue a build, I choose to build with local sources plus a shelveset. Then I specify which shelveset, and I have the option to check-in my changes if the build succeeds. Splendid!

Disabling ReSharper

ReSharper is a great development tool that has a lot of offerings, and I generally don’t have complaints about it. The one thing that does irk me, though, is that it can cause solutions containing a large number of projects to load very slowly in Visual Studio.

I found that a simple workaround for this is to just disable ReSharper before opening the solution. This task is accomplished easily in two different ways. The first is to just go to Tools > Options > ReSharper in Visual Studio, and click the Suspend button. To re-enable the interface, click the Resume button in the same location. The second is to use the ReSharper_Suspend & ReSharper_Resume or ReSharper_ToggleSuspended commands in Visual Studio’s Command Window. (Bonus tip! If you need to suspend/resume frequently, map the commands to toolbar buttons.)

VS2010 Extensions

I just upgraded to VS2010 at work this week, and I feel like a kid in a candy store with all of the extensions available online. ( Here are some of the ones that I’ve already fallen in love with…

Team Foundation Server Power Tools April 2010:
TFPT.exe; PowerShell Cmdlets for VSTS; Windows Shell Extensions

PowerCommands for Visual Studio 2010:
Copy/paste classes & references; email code snippets; open containing folder from Solution Explorer

Collapse Selection in Solution Explorer:
Recursively collapse the selected node in Solution Explorer

Search Work Items for TFS 2010:
Search TFS work items from a menu bar textbox

%d bloggers like this: