# Integrating CSharp unit tests with add\_test

**URL:** https://discourse.cmake.org/t/integrating-csharp-unit-tests-with-add-test/10288
**Category:** Code
**Tags:** os:windows, comp:msvc, gen:vs
**Created:** [March 5, 2024, 8:54am UTC](https://discourse.cmake.org/t/integrating-csharp-unit-tests-with-add-test/10288 "2024-03-05T08:54:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Nino\_Stanusic](https://discourse.cmake.org/user_avatar/discourse.cmake.org/nino_stanusic/32/4378_2.png) [@Nino\_Stanusic](https://discourse.cmake.org/u/Nino_Stanusic)
#### Post date: [March 5, 2024, 8:54am UTC](https://discourse.cmake.org/t/integrating-csharp-unit-tests-with-add-test/10288/1 "2024-03-05T08:54:43Z")

</div>

Hello everytone,

**The goal:**

I want to achieve csharp unit testing alongside C++ tests in cmake.

we have a C++ project that uses the UseSWIG module to generate our C# bindings. And we would like to test them.

**The current state**

The source code to achieve a CSharp library that is able to run tests:

```cmake
enable_language(CSharp)
add_library(csharp_unit_tests SHARED)

target_sources(csharp_unit_tests PRIVATE UnitTests.cs) 

set_property(TARGET csharp_unit_tests PROPERTY
	VS_DOTNET_REFERENCES
	"Microsoft.CSharp"
	"System"
)

set_property(TARGET csharp_unit_tests PROPERTY
	VS_PACKAGE_REFERENCES
	"xunit_2.7.0"
	"xunit.runner.visualstudio_2.5.7"
	"Microsoft.NET.Test.Sdk_17.9.0"
)

```

**Results**  
This runs my unit tests in the test explorer of VS2022.

**The issue**  
My first idea for now was to create an [add\_test](https://cmake.org/cmake/help/latest/command/add_test.html):

```auto
add_test(NAME COMMAND dotnet.exe test tests/csharp/csharp_unit_tests.csproj)

```

When trying to run test from cmd following the [xunit tutorial](https://xunit.net/docs/getting-started/netcore/cmdline). An error occurs in the dependent ZERO\_CHECK target.

```auto
\build\ZERO_CHECK.vcxproj(35,3): error MSB4019: The imported p
roject "D:\Microsoft.Cpp.Default.props" was not found. Confirm that the expression in the Impor
t declaration "\Microsoft.Cpp.Default.props" is correct, and that the file exists on disk.

```

When running the command in powershell outside of CMake the same error occurs.

Is there a better way to achieve this or how to resolves the ZERO\_CHECK issue so i can run my tests through ctest?

Thank you 🙂

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [March 3, 2025, 4:04pm UTC](https://discourse.cmake.org/t/integrating-csharp-unit-tests-with-add-test/10288/2 "2025-03-03T16:04:58Z")

</div>

Does that file exist? Where in CMake’s generated projects does it appear? Can you trace it back to the CMake code that causes it to be referenced?
