2009-01-25 97 views
11

可能重复:
.NET windows application, can it be compressed into a single .exe?我可以在exe中包含dll(在Visual Studio中)吗?

运行我的应用我需要AxInterop.WMPLib.dllInterop.WMPLib.dll,它们位于调试和发布文件夹。有没有办法将这些dll包含到exe中,这样我的应用程序只能在一个文件中使用?

+0

尽管这是可能的,但我并不喜欢它。共享库的要点是它们在程序之间共享。如果程序发现它们尚未安装,那么下载它们怎么办? – 2009-01-25 02:07:47

回答

19

只要你的DLL是.NET程序集,那么ILMerge应该能够将你的exe和它的所有依赖关系合并到一个文件中。

+1

这在ILMerge页面上也有说明,但对于WPF应用程序,请使用以下内容:http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr -via-c-third-edition.aspx – Menefee 2012-07-26 17:51:37

0

将它们包含为嵌入式。然后您可以在运行时提取它们。

-2

例如,将x.dll添加到项目并将其生成操作设置为嵌入式资源。

要提取:

string AppPath=Assembly.GetExecutingAssembly().Location; 
Assembly ThisAssembly=Assembly.LoadFrom(AppPath); 
System.IO.Stream fs=ThisAssembly.GetManifestResourceStream("yourproectname.x.dll"); 
int ssize=(int)fs.Length; 
byte [] buf=new byte[ssize]; 
fs.Read(buf,0,ssize); 
fs.Close(); 
+2

前两行是“Assembly thisAssembly = Assembly.GetExecutingAssembly();”的不必要复杂。然后在最后缺少这一行:“Assembly.Load(buf);”。最后,这是一个可怕的解决方案,因为您只能通过反射访问加载的程序集。 – 2009-01-25 02:23:35

0

是的,我离开了代码写入文件了...

FileStream so=new FileStream("c:\\\wherever\\\x.dll",FileMode.Create); 

so.Write(buf,0,ssize); 

so.Close(); 

无需额外的工具。

4

您可以使用像boxedapp或thinstall工具...

4

我也推荐boxedapp。这是伟大的应用程序!

+2

我更喜欢使用BoxedApp。这是如此简单! – MastAvalons 2011-12-15 16:55:28

相关问题