Integrating a .exe file into a visual studio proje

2020-03-31 03:13发布

broken to bare-bones scene: I have a program in c# that calls a .exe inside cmd(using process.start), passing some required arguments.

What i'm trying to do: Include the exe into the project so that i don't have to call cmd.

Any idea?

3条回答
狗以群分
2楼-- · 2020-03-31 03:57

You can add an exe as an embedded resource (just right click on a folder in the Solution explorer, Add Existing Item, then get properties on it and set it to be Embedded Resource). However, you may not be able to easily execute it in place - you'll need to save it to disk and then execute it (which doesn't solve your stated problem of having to ShellExecute the .exe file, but does solve the problem of having to ship more than one file to the end user).

If you have the source code, then you'll be able to repackage the exe as a dll, or integrate it directly into your program code.

查看更多
再贱就再见
3楼-- · 2020-03-31 03:59

If you just want to include so you don't have to ship two files then just include it into the project as "embedded resource" (see project item options) and then you can call ResourceManager.GetStream and write it to file and call Process.Start.

If you want integrate the functions of that exe so that the exe is not needed anymore (no Process.Start) then you need the source code...

EDIT: the "write to file" is not necessary if the exe is .NET - then you can directly load it from the resource stream as Assembly/AppDomin and execute it.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-03-31 04:11

If the exe is a .NET assembly, you could use ILMerge to merge the exe into your main assembly. You can then invoke the code in the exe directly.

查看更多
登录 后发表回答