Convert a standard C# project into a Unit Test project

April 02, 2017

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):

[code lang=“xml”] Debug AnyCPU {93F28F24-AD9B-4839-8697-6DA48BAB2048} Library Properties MyProject.UnitTests MyProject.UnitTests v4.5.2 512




All you need to do is add the correct ProjectTypeGuids:

[code lang="xml"]
<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



Profile picture

A blog about one man's journey through code… and some pictures of the Peak District
Twitter

© Paul Michaels 2022