The other day I had to add a library to our third party tools folder (nmock2 actually) but in order to use it in our code I had to ensure that it had a strong name. Now one way I could have done this is to have downloaded the source code for the assembly and then recompiled adding a strong name. However I found a simpler solution on Adrian Hara's blog that showed how I could use the ILMerge tool from MS Research to achieve the same effect but without the hassle (and there would have been) of recompiling the unsigned module.
Essentially what you do is sign your own assembly and merge in the unsigned assembly, creating a single signed assembly package. This does requires some code compilation but not the original code from the unsigned third party assembly, just some of your own. Being a lazy so an so (:-) I decided to automated the process:
- Create temporary assembly (ILMerge.dummy.dll) with a correct strong name. This is my favourite bit as the code I'm using to create this assembly doesn't exist (e.g. echo.>tmp.cs) .
- Run ILMerge on this assembly together with the third party one, also specifying the strong name.
- Delete the temporary assembly
with a command file and that's it.
Here's a batch file snippet that I used to do all of this:
By the way the XXXXX is an identifier I've used to distinguish the output from the original assembly (e.g. preet.dll becomes a signed preet.XXXXX.dll). To use it just save the code snippet above use like this: