2011-06-04 158 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/