Is it possible to include a binary file in my project and use it?

I have a binary file that is used as a command line tool to manage some files - tool.exe. I would like to include this in my Visual Studio 2008 project and use it from my C # code. I have it in the Resources folder, which also has some other files that my project uses.

I would like to do something like Process myproc = Process.Start("Resources/tool.exe"); but I believe that C # has a problem with this because it is looking in the file system, not the project.

How can I do that?

+4
source share
3 answers

You pretty much describe the right way to do this. You need to make sure that the binary is configured to copy to the correct location with respect to your application - you do this by setting the Build action to content (in the file properties), so it will be copied to the correct location.

This build action defaults the Copy to Ouput directory property Copy to Ouput directory Copy Always , which in this case is safe to be Copy if newer . Make sure it is one of these two.

See details for details.

+4
source

do Process myproc = Process.Start("./Resources/tool.exe"); if I understand your question well

0
source

Yes, your application will search the file system compared to your application .exe file.

You can include executable files in your project and copy them to the output directory. After adding the binary file to the project, select it and go to its properties. “Build action” should be set to “Content”, and “Copy to output directory” should be set to “Always copy” or “Copy if new”.

It may be a little harder to get the folder created in your output directory and add a file to it; You may need to install the binary in the same directory as your executable. One place to look is your project creation activities; you can add post-build scripts that configure the folder and move the binary to the desired location.

0
source

Source: https://habr.com/ru/post/1312356/


All Articles