Skip to content

CSharp: reference imported C# targets

I would like to be able to use imported C# targets the way I can use imported C++ targets as well. This means:

  • write/generate an import file which contains IMPORTED targets with C# assemblies
  • use target_link_libraries() on C# targets and imported C# targets

This should look something like this:

include(MyImportFile.cmake)

add_executable(ReferenceImport ReferenceImport.cs)

target_link_libraries(ReferenceImport namespace:ImportedTarget)

This behavior would be consistent to the current approach how C# targets can reference other C# targets if both are built in the same project.

Why do I want this?

  • To be able to provide imported targets for 3rd party assemblies we use in some cases
  • To be able to adhere the proposed way of Effective CMake

What do I need to know?

  • what would be the best way to tell an imported target is a C# target?

This MR is a working example which I would like to evaluate to see how things should be done best. A testcase is included for everyone who want to take a look.

Edited by Michael Stürmer

Merge request reports