只需在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/
我不能嵌入dll文件成EXE? – cvwerfwe 2011-06-04 10:25:44
你有你的dll文件的源代碼嗎? – Serghei 2011-06-04 10:29:17
Devexpress dlls – cvwerfwe 2011-06-04 10:35:13