只需在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