2011-06-04 154 views
0

可能重复:
.NET windows application, can it be compressed into a single .exe?运行exe文件,除非使安装(嵌入DLL到EXE)

我有一个项目,我使用了很多的.dll文件在这个项目。当我尝试在另一台电脑上运行我的项目时,它无法工作。因为我只使用.exe。我想我必须做安装项目。但是我想运行我的程序而不做安装项目。如何将.dll文件嵌入到我的exe文件中? 我正在使用Visual Studio 2010. 顺便说一下我的英语,但谷歌翻译的英语比我的差。 谢谢。

回答

1

你只需要将你的dll文件与exe文件复制到同一个目录。 ,你可以使用ILMerge util

你可以从msdn

+0

我不能嵌入dll文件成EXE? – cvwerfwe 2011-06-04 10:25:44

+0

你有你的dll文件的源代码吗? – Serghei 2011-06-04 10:29:17

+0

Devexpress dlls – cvwerfwe 2011-06-04 10:35:13

1

使用ILMerge.exe下载它,你可以合并你的EXE和DLL在一起。


您还可以使用netz.exe作为替代EXE压缩机&打包机。

0

只需在Visual Studio中右键单击您的项目,选择项目属性 - >资源 - >添加资源 - >添加现有文件... 并将下面的代码包含到您的App.xaml.cs或同等版本中。

public App() 
{ 
    AppDomain.CurrentDomain.AssemblyResolve +=new ResolveEventHandler(CurrentDomain_AssemblyResolve); 
} 

System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) 
{ 
    string dllName = args.Name.Contains(',') ? args.Name.Substring(0, args.Name.IndexOf(',')) : args.Name.Replace(".dll",""); 

    dllName = dllName.Replace(".", "_"); 

    if (dllName.EndsWith("_resources")) return null; 

    System.Resources.ResourceManager rm = new System.Resources.ResourceManager(GetType().Namespace + ".Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly()); 

    byte[] bytes = (byte[])rm.GetObject(dllName); 

    return System.Reflection.Assembly.Load(bytes); 
} 

这是我原来的博客文章: http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/