✅ C# project that contains C++ on mac
Hey guys, so I want to try getting a C# project working that also contains c++ compiled into a library, but mac is making this quite difficult. I can compile the .dylib manually and compile my .cs file using the
dotnet command, but when it comes to actually making this into a managable project I am a bit stuck. It seems normally what I would want to do is use a .vcxproj file to compile into a library, and then in a .sln file have some sort of settings to build both my .csproj and .vcxproj together. I tried to just do this with dotnet, but it seems the dotnet command does not support solutions with .vcxproj files.
I tried msbuild and dotnet-vcxproj but they both fail for the same reason:
heres my .vcxproj
im feeling super lost, I have no idea how to write vcxproj files and the documentation really doesn't do much to explain it, since they are supposed to be made with visual studio. Visual studio for mac cannot create c++ projects. If theres any help or directions anyone can offer, please do. Thanks!3 Replies
@butteredcoffee vcxproj requires stuff that isn't part of the .net sdk, and it uses Microsoft's C++ compiler anyways, which you won't have on macOS.
Use a Mac-native solution to build your C++, like cmake or a Makefile.
im trying to set it up so I can just run the whole thing in one go
I got cmake to custom build my csproj
so now its just a visual studio code thing to run it when I press play
I can close but if anyone has additional help lmk. I am def hacking this together so if theres a better way on mac please tell me
@butteredcoffee you might have luck with https://github.com/vezel-dev/zig-sdk 🙂
you can use it to cross-compile C/C++ & use it in .NET projects
it uses the zig compiler
alternatively, you could set up another type of C++ project (e.g., cmake, makefile, etc.), and then adjust your csproj to pick up the native from it and/or execute the build from msbuild