Include referenced assembly without having to keep application in same directory as the referenced assembly
I am using HTMLAgilityPack
with my C# winform
application. I loaded HTMLAgilityPack from my hard drive using Visual Studio
, as a Referenced Assembly. I the开发者_JAVA百科n build my application and copy the output executable file to a new directory. If HTMLAgilityPack is not in the same directory as my output executable, an error occurs when attempting to run my executable saying that the 'reference could not be found.' Is there some way to have the reference embedded into the executable file so that users will not need to carry around HTMLAgilityPack with them whenever they wish to move the file?
I look forward to your responses,
Evan
Yes, you can do that - but it isn't exactly trivial. You would subscribe to the AppDomain.CurrentDomain.AssemblyResolve
event, and when raised, check that it is looking for html agility pack (via the event args), then fetch the assembly BLOB from the embedded resource, use Assembly.Load(theBlob)
, and return the Assembly
instance.
Another, simpler, approach might be ilmerge.exe
Finally, the GAC would avoid the need to have the file locally... but requires having it formally installed centrally instead. To be honest I would avoid the GAC here.
You can use ILMerge utility to compine several assemblies into single file
ILMerge.exe /t:winexe /out:test.exe test1.exe test2.dll
精彩评论