Convert a standard C# project into a Unit Test project

I recently (accidentally) created a Unit Test project as a standard C# class library. Although you don’t need to change this to a test library (it basically just gives you the test icon instead of the class icon), I felt that, if I wanted to do this, it shouldn’t require that I delete and recreate the project.

To change the project type

If you open the csproj for a class library, it looks like this (or some of it does):

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{93F28F24-AD9B-4839-8697-6DA48BAB2048}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>MyProject.UnitTests</RootNamespace>
    <AssemblyName>MyProject.UnitTests</AssemblyName>
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>

All you need to do is add the correct ProjectTypeGuids:

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

References

https://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs

http://stackoverflow.com/questions/2911565/what-is-the-significance-of-projecttypeguids-tag-in-the-visual-studio-project-fi

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.