C
C#8mo ago
MrScautHD

Compile Native Lib

I wanna ask how i can build a C project in my .csproj to use the .dll from it, do someone know or has a example for me?
27 Replies
Jimmacle
Jimmacle8mo ago
you could set up your C# project to run your C compiler on build then the usual pinvoke from there
Jimmacle
Jimmacle8mo ago
Exec Task - MSBuild
Learn to use the MSBuild Exec task to run a specified program or command by using the specified arguments.
MrScautHD
MrScautHDOP8mo ago
i never done something like that before, do you maybe have a example for me? thx, but do you have some examples?
Jimmacle
Jimmacle8mo ago
yeah, on that page i haven't done exactly what you want for any projects, this is the general solution to running an arbitrary program as part of a C# build see https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-targets?view=vs-2022 as well
MrScautHD
MrScautHDOP8mo ago
this tell me just to run a command
No description
Jimmacle
Jimmacle8mo ago
yeah that's what it's for the command will depend on how your C project is set up and what build system you're using for that
MrScautHD
MrScautHDOP8mo ago
CMake
Jimmacle
Jimmacle8mo ago
so you'd run whatever command you need to make cmake build it
MrScautHD
MrScautHDOP8mo ago
btw would it possible to automatically download the C lib?
Jimmacle
Jimmacle8mo ago
download from where?
MrScautHD
MrScautHDOP8mo ago
from .csproj
Jimmacle
Jimmacle8mo ago
no like where is the C lib?
MrScautHD
MrScautHDOP8mo ago
Github tags
Jimmacle
Jimmacle8mo ago
i mean you could probably do that with msbuild too if you wanted to
MrScautHD
MrScautHDOP8mo ago
do you know how?
Jimmacle
Jimmacle8mo ago
yes, by looking at the msbuild docs about targets that i linked earlier
MrScautHD
MrScautHDOP8mo ago
kk
Jimmacle
Jimmacle8mo ago
why do you need to both download the library and build it from source?
MrScautHD
MrScautHDOP8mo ago
yea i want to download it and build it
Jimmacle
Jimmacle8mo ago
?
MrScautHD
MrScautHDOP8mo ago
then i just need to write the new version of the program like <ReleaseTag>5.0<ReleaseTag> i doing a wrapper to c#
Jimmacle
Jimmacle8mo ago
you wouldn't want to do that with msbuild, you'd add the repo as a submodule or something
MrScautHD
MrScautHDOP8mo ago
well then i wanna do that
Jimmacle
Jimmacle8mo ago
if you're writing a wrapper why are you concerned with building the native lib in the first place? you don't need to do that to build your wrapper
MrScautHD
MrScautHDOP8mo ago
? i mean i need the .dll for any platform
Jimmacle
Jimmacle8mo ago
yeah but why is that a concern of your project you haven't really explained what the native lib is or why you need to build it this way
MrScautHD
MrScautHDOP8mo ago
i would just like too create it like that but a submodule is no bad idea too and then compile it by runing the cmake command
Want results from more Discord servers?
Add your server