Passing complie definitions to a include_external_msproject target

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.

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

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 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