Ziv
Ziv

Reputation: 2421

How do I define a C# Unit Test Project using CMake?

I'm converting some existing C# projects to be defined in CMake -- moving from the previous include_external_msproject() directive to the newer full support for C#.

But I'm not seeing how to convert projects of the Visual C# Unit Test Project type. I'm able to build them as libraries, and compile them successfully -- but Visual Studio doesn't show them as unit test projects, just as regular libraries. Most crucially, the tests aren't visible to the Test Explorer.


Things I've already tried include:

I'm using Microsoft Visual Studio Professional 2015, CMake 3.13.2, .NET Framework 4.5.2 (but I suspect the issue isn't specific to my particular version combination).

Upvotes: 4

Views: 1483

Answers (2)

Paweł Iwaneczko
Paweł Iwaneczko

Reputation: 929

Thanks @bhardwajs, your answer helped me.
You can also add TestProjectType to global properties:

set_target_properties(${target_name} PROPERTIES
VS_GLOBAL_TestProjectType "UnitTest"
VS_GLOBAL_PROJECT_TYPES "{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}")

Upvotes: 1

bhardwajs
bhardwajs

Reputation: 534

Manually adding <TestProjectType>UnitTest</TestProjectType>, made my unit test project show up as unit test. Trying to figure out how to do that using cmake.

Update: the following shows the project as unittest

set_target_properties(${target_name}
PROPERTIES
VS_GLOBAL_PROJECT_TYPES "{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
)

Documentation for VS_GLOBAL_PROJECT_TYPES is here. I found this documentation for Project Guid: Visual Studio project type guids

Upvotes: 5

Related Questions