问题
There are a lot of posts on here about this, I'm using this code from another SO post and placing a delegate assignation in my Main() method. None of the other posts have directly answered my question.
I've got my third party assembly embedded as a resource but when I fire up the app:
- I'm getting a TypeInitializationException with an inner of FileNotFoundException. It's trying to find the assembly on the file system and failing.
- it's never getting to the Main method, where the event handler for AssemblyResolve is assigned
I have two assembly refs that are embedded in my Resources.resx, one is a third party tool (command line parser) and the other is a Library file where the meat of the application resides.
Maybe this isn't possible with a console app? Seems unlikely but I don't see a way around it.
Re: ILMerge etc: I'd like to get this done entirely in code without involving any tools. Reason: I don't want to have source code in the repository that requires other team members to install a tool that they probably don't have already. If that's not possible then ILMerge looks like the next best option.
回答1:
Consider using ILMerge to merge the assemlies into one rather than embedding as a resource. This is download site for ILMerge.
You would merge your third party assemblies into your console app.
回答2:
You could also look at application virtualization tools like XenoCode. They can package multiple assemblies (including the .net framework itself) into a stand alone executable.
回答3:
If it is mixed mode assembly, it has to reside on the disk. Some limitation or something.
来源:https://stackoverflow.com/questions/2418539/how-can-i-embed-an-assembly-into-a-console-application-without-ilmerge