4

I have a binary that's used as a command-line tool to manipulate 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 a folder called "Resources" which also has some other files my project uses.

I would like to do something like Process myproc = Process.Start("Resources/tool.exe"); but I believe C# has an issue with this because it's looking in the file system rather than the project.

How can this be done?

Adam S
  • 8,945
  • 17
  • 67
  • 103

3 Answers3

4

You are pretty much describing the correct way to do this. You have to make sure that the binary file is set to be copied to the correct location relative to your application - you do this by setting the Build action to content (in the file properties), so it will get copied to the correct location.

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

See this SO question and answers for more details.

Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • Also, I'd like to add that while creating the setup project for my application, I had to make sure to, in the FileSystem>Application Folder, Add "Project Output" of "Content Files" to fix windows not being able to locate those binaries. – Adam S Jun 10 '10 at 17:23
0

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

Svisstack
  • 16,203
  • 6
  • 66
  • 100
0

Yes, your application will be looking in the file system, relative to your application .exe file.

You can include binaries in your project, and have them copied to the output directory. After adding the binary to your project, select it and go to its properties. "Build action" should be set to "Content", and "Copy to Output Directory" should be set to "Copy always" or "Copy if newer."

It might be a little harder to get a folder built in your output directory, and have the file added to that; you may have to settle for having the binary in the same directory as your executable. One place to look is in your project build actions; you can add post-build scripts that set up the folder and move the binary to the proper location.

Cylon Cat
  • 7,111
  • 2
  • 25
  • 33