how to produce a mix of dll and exe in one C# project in visual studio or other build tools?

谁都会走 提交于 2019-12-02 04:45:00

I'm not sure what the motivations for your question are, as you can reference a .Net executable as if it were a dll anyway, but you could consider copying the exe file to a dll file with the same name (yes it's a hack but not sure of your motivations).

You can automate this process using a Visual Studio post-build event for your project. This will handle creating the dll copy each time you have a successful build:

copy "$(TargetPath)" "$(TargetDir)$(TargetName).dll"

Technically, a mix of exe and dll would be simply an exe. Nothing's wrong with using it as a library e.g reference to it in other projects.

First we need to be clear that both "exe" and "dll" are fundamentally the same but the difference lies in how windows interacts with them.

When windows loads a dll, it runs the initialization code and then leaves it alone. Functions in the dll are called if they are explicitly referenced by an application. Another thing, when dll gets crashed it not only crashes itself but also the application as the dll runs in the memory of the parent application.

When windows load an exe, the exe's initialization code is responsible for creating what is called as "message pump", nothing but a program loop which runs as long as the application is running. The message pump request messages from the operating system. Windows keep track of the application as a separate task. It allocates separate memory for both the exe and the application using that exe. The memory area in which each exe runs is called "Process Space".

Dan Appleman - Developing ActiveX Components with Visual Basic 5.0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!