# Passing complie definitions to a include\_external\_msproject target

**URL:** https://discourse.cmake.org/t/passing-complie-definitions-to-a-include-external-msproject-target/15233
**Category:** Code
**Tags:** os:linux, os:windows, lang:csharp
**Created:** [October 11, 2025, 8:30am UTC](https://discourse.cmake.org/t/passing-complie-definitions-to-a-include-external-msproject-target/15233 "2025-10-11T08:30:54Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Tarun](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tarun/32/5849_2.png) [@Tarun](https://discourse.cmake.org/u/Tarun)
#### Post date: [October 11, 2025, 8:30am UTC](https://discourse.cmake.org/t/passing-complie-definitions-to-a-include-external-msproject-target/15233/1 "2025-10-11T08:30:54Z")

</div>

I have an external csproj which I want build in both linux and windows alongside other regular targets(non-custom targets) that are created using cmake. The idea was to create a custom target and use dotnet 8.0 and it’s cli.

```auto
add_custom_target(ExternalCSharp 
                  ALL
                  COMMAND dotnet build path/to/proj 
                 -p:DefineConstants="MY_DEFINITION")
                  

```

This, however, doesn’t add the csproj to the visual studio solution when I open the top level solution on windows. Therefore I had to use the include\_external\_msproject to include it to the solution

```auto
if(Win32)
include_external_mstarget(ExternalCSharp path/to/csproj .....other properties)

endif()

if(LINUX)
add_custom_target(ExternalCSharp 
                  ALL
                  COMMAND dotnet build path/to/proj 
                 -p:DefineConstants="MY_DEFINITION")
                  
endif()

```

Now I can open the solution and build the project with the build parameters I require, which is perfect . The only problem is when I plan to automate the entire build process for both OS’s using the cmake –build command I want to be able to pass the compile definitions(In this example: MY\_DEFINITION) to the windows build as well.

I tried using [target\_compile\_definitons](https://cmake.org/cmake/help/latest/command/target_compile_definitions.html) to the include\_external\_mstarget but it throws an error (as expected) because this target wasn’t created through add\_executable() or add\_library().

I wanted to know if there is a way to

a) Add a external csproject to the solution in Windows **and**

b) be able to build the said project with the specified compile definitions provided when building through cmake –build

Thank you
