I am using HTMLAgilityPack with my C# winform application. I loaded HTMLAgilityPack from my hard drive using Visual Studio, as a Referenced Assembly. I then 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.AssemblyResolveevent, 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, useAssembly.Load(theBlob), and return theAssemblyinstance.Another, simpler, approach might be
ilmerge.exeFinally, 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.