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:
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:
add_test(NAME COMMAND dotnet.exe test tests/csharp/csharp_unit_tests.csproj)
When trying to run test from cmd following the xunit tutorial. An error occurs in the dependent ZERO_CHECK target.
\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