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