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:
    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
  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: http://www.mztools.com/articles/2008/mz2008017.aspx

Advertisements

2 thoughts on “Convert a Class Library to a Test Project in Visual Studio”

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s