C
C#4mo 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
Jimmacle4mo ago
you could set up your C# project to run your C compiler on build then the usual pinvoke from there
Jimmacle
Jimmacle4mo ago
Exec Task - MSBuild
Learn to use the MSBuild Exec task to run a specified program or command by using the specified arguments.
MrScautHD
MrScautHD4mo ago
i never done something like that before, do you maybe have a example for me? thx, but do you have some examples?
Jimmacle
Jimmacle4mo 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
MrScautHD4mo ago
this tell me just to run a command
No description
Jimmacle
Jimmacle4mo 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
MrScautHD4mo ago
CMake
Jimmacle
Jimmacle4mo ago
so you'd run whatever command you need to make cmake build it
MrScautHD
MrScautHD4mo ago
btw would it possible to automatically download the C lib?
Jimmacle
Jimmacle4mo ago
download from where?
MrScautHD
MrScautHD4mo ago
from .csproj
Jimmacle
Jimmacle4mo ago
no like where is the C lib?
MrScautHD
MrScautHD4mo ago
Github tags
Jimmacle
Jimmacle4mo ago
i mean you could probably do that with msbuild too if you wanted to
MrScautHD
MrScautHD4mo ago
do you know how?
Jimmacle
Jimmacle4mo ago
yes, by looking at the msbuild docs about targets that i linked earlier
MrScautHD
MrScautHD4mo ago
kk
Jimmacle
Jimmacle4mo ago
why do you need to both download the library and build it from source?
MrScautHD
MrScautHD4mo ago
yea i want to download it and build it
Jimmacle
Jimmacle4mo ago
?
MrScautHD
MrScautHD4mo 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
Jimmacle4mo ago
you wouldn't want to do that with msbuild, you'd add the repo as a submodule or something
MrScautHD
MrScautHD4mo ago
well then i wanna do that
Jimmacle
Jimmacle4mo 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
MrScautHD4mo ago
? i mean i need the .dll for any platform
Jimmacle
Jimmacle4mo 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
MrScautHD4mo 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