Preamble: I am trying to integrate my C# csproj with the rest of our C++ and C++/CLI code-base cmake build. I have received advise against trying to do this, because CMake doesn't co-operate well with .NET in Visual Studio, but after implementing some customizations, I feel that I am very close.
Part of my customization is using the configure_file command to edit the csproj file at CMake time, to customize it depending on the type of build (e.g. x86, x64) that is happening.
The problem is that I use some ProjectReference tags to reference the C++/CLI projects:
<ProjectReference Include="..\..\WrapperProject\WrapperProject.vcproj">
<Project>{7BD6E175-CDD1-4F8D-A3B2-0AC862E62C03}</Project>
<Name>WrapperProject</Name>
</ProjectReference>
... and the GUIDs cannot remain static, since they change for the project whenever the CMake cache is rebuilt (correct me if I'm mistaken).
So what I would like to do is find our at CMake time what GUIDs are planned for these projects and to edit the vcproj file accordingly.
Google tells me that people are able to use 'set_property' to set the GUID, like so:
set_property(CACHE ${target_name}_GUID_CMAKE PROPERTY VALUE ${MY_GUID} )
... but I can't seem to find the getter equivalent. I've tried things like this:
get_property(WRAPPER_GUID CACHE INTERNAL PROPERTY WrapperTargetName_GUID_CMAKE)
... without luck. Your help is appreciated!
Your syntax is slightly off. You probably meant:
However, this is a relatively convoluted way to get the value. You can just do:
Finally, this isn't ideal since the GUID isn't available until after the first run of CMake. So for a fresh build tree, you'd have to run CMake twice before this would be usable.
After playing around with this more, I realized what Fraser pointed out - that this method wouldn't always work because I can't expect the GUIDs to be available on a fresh run of CMake. So I went the route that I had seen suggested on the CMake mailing list, which is to explicitly set the GUID values myself.
So in the CMakeLists.txt for each C++/CLI wrapper project, I have something like this:
And in the C# project CMakeLists.txt, I have this:
... and then the CMAKE_WRAPPER_GUID is used as a variable in the .csproj file that is populated during the configure_file command.
I'm not sure if this is efficient, but it seems to work!