所以我必须加载一些MetroFramework.Dll并且它们在合并时工作正常,但我也使用NAudio.dll,一旦合并到exe文件中就根本不加载。 我先试用了这段代码:
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
Assembly thisAssembly = Assembly.GetExecutingAssembly();
//Get the Name of the AssemblyFile
var name = args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll";
//Load form Embedded Resources - This Function is not called if the Assembly is in the Application Folder
var resources = thisAssembly.GetManifestResourceNames().Where(s => s.EndsWith(name));
if (resources.Count() > 0)
{
var resourceName = resources.First();
using (Stream stream = thisAssembly.GetManifestResourceStream(resourceName))
{
if (stream == null) return null;
var block = new byte[stream.Length];
stream.Read(block, 0, block.Length);
return Assembly.Load(block);
}
}
return null;
};
它只加载MetroFramework ...而不是NAudio.dll
然后我改为现在的代码:
AppDomain.CurrentDomain.AssemblyResolve += (sender, arg) =>
{
if (arg.Name.StartsWith("NAudio")) { return Assembly.Load(VASBUILD.Properties.Resources.NAudio); }
else if (arg.Name.StartsWith("MetroFramework")) { return Assembly.Load(VASBUILD.Properties.Resources.MetroFramework); }
else if (arg.Name.StartsWith("MetroFramework_Design")) { return Assembly.Load(VASBUILD.Properties.Resources.MetroFramework_Design);}
else if (arg.Name.StartsWith("MetroFramework_Fonts")) { return Assembly.Load(VASBUILD.Properties.Resources.MetroFramework_Fonts); }
else
{ return null; }
};
为什么它不起作用?是否需要使用其他方式加载?