在项目引用里找到DLL引用,“复制到本地”属性改为False,添加DLL到资源
Public Sub New()
'加载DLL到exe的事件
AddHandler AppDomain.CurrentDomain.AssemblyResolve, New ResolveEventHandler(AddressOf CurrentDomain_AssemblyResolve)
InitializeComponent()
End Sub
'把DLL加载到EXE中
Private Function CurrentDomain_AssemblyResolve(sender As Object, args As ResolveEventArgs) As System.Reflection.Assembly
Dim dllName As String = If(args.Name.Contains(","), args.Name.Substring(0, args.Name.IndexOf(","c)), args.Name.Replace(".dll", ""))
dllName = dllName.Replace(".", "_")
If dllName.EndsWith("_resources") Then
Return Nothing
End If
Dim rm As New System.Resources.ResourceManager([GetType].Namespace & ".Resources", System.Reflection.Assembly.GetExecutingAssembly())
Dim bytes As Byte() = DirectCast(rm.GetObject(dllName), Byte())
Return System.Reflection.Assembly.Load(bytes)
End Function
本文介绍了如何在项目中处理DLL引用,通过将复制到本地属性设为False,并将DLL添加到资源中,以避免硬链接和提高性能。作者还展示了如何使用AssemblyResolve事件来动态加载DLL。
342

被折叠的 条评论
为什么被折叠?



