在.NET应用程序中嵌入EXE和所需的DLL并在运行时执行
我有一个现有的 EXE 和 DLL 文件(均为非托管),我希望将它们嵌入到我的 C# 应用程序中并在 C# 应用程序的运行时执行。当通过命令行或资源管理器正常执行时,EXE 要求 DLL 与 EXE 位于同一目录中。我怎样才能:
1) 在我的应用程序中嵌入 EXE 和 DLL 并通过 C# 代码执行它们?
2) 确保EXE能够访问其依赖的DLL文件?
谢谢!
I have an existing EXE and DLL file (both unmanaged) that I'd ideally like to embed in my C# app and execute at runtime of the C# app. The EXE, when executed normally via command-line or Explorer, requires the DLL to be in the same directory as the EXE. How would I be able to:
1) Embed the EXE and DLL in my app and execute them via C# code?
2) Make sure that the EXE will be able to access its dependent DLL file?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将它们放入项目嵌入资源中。
当您的程序运行时,从资源中提取它们,复制到已知位置并通过 Process.Start 执行
Put them in Project embedded Resources.
When your program runs extract them from Resources, copy into known location and execute via Process.Start
将文件添加为嵌入资源。然后,您可以将它们导出到代码中您喜欢的任何位置。使用 System.Diagnostics.Process 类来运行它。
编辑:
您可能还想缓存位置名称,以便在 C# 应用程序退出时可以删除文件(如果您想在自己退出后进行清理)
Add the files as embedded resources. You can then export them to wherever you like in your code. Use the System.Diagnostics.Process class to run it.
Edit:
You may also want to cache the location name so that you can delete the files when your C# application exits (if you want to be nice and cleanup after yourself that is)
有.NETZ,我曾经成功使用过一次。看来该工具还在某种程度上支持本机非托管DLL。
也许它可以为您提供一些关于您实际所需的解决方案的想法。
There is .NETZ which I have used once successfully. It seems that the tool also supports native unmanaged DLLs to some degree.
Maybe it helps as a pointer to give you some ideas for your actual desired solution.