About the author

Steven Harmansteven harman :: makes sweet software with computers!

For recent posts and more about me, scroll to the bottom.

Sponsors

Subscribe

  • Subscribe to my feed. via RSS
  • Subscribe via email via email

Signing 3rd Party Assemblies without Recompiling

We recently ran into an issue where upon pulling some new 3rd party dependencies into our product our CI pipeline broke! I when I say broke, I mean it came to a screeching halt!

We were totally unable to compile in Release mode due to the new dependencies not being strongly named and signed. The error message in the build log was

CSC : error CS1577: Assembly generation failed -- Referenced assembly 'MvcContrib.FluentHtml' does not have a strong name

Sign it yourself!

Eric Hexter, of the MvcContrib team, pointed me to a thread explaining how to strongly-name and sign the assembly without having to recompile it. After a few failed attempts, I ended up using the IL Disassembler and Assembler to get the job done. The template for a single DLL follows.

   1:  > ildasm {path\to\assembly}.dll /out:{path\to\assembly}.il
   2:  > move {path\to\assembly}.dll {path\to\assembly}.dll.orig
   3:  > ilasm {path\to\assembly}.il /dll /key={path\to\SigningKey}.snk

The second line could really just be a delete, but whatever. The point is, the third line is going to output a new DLL of the same name as the original, so get rid of the original first.

After that, I committed the new assembly into our source tree, the CI build pipeline kicked off, and we were back to green!

Technorati Tags: ,,

What others are saying.

# re: Signing 3rd Party Assemblies without Recompiling
Gravatar The Dentist
Oct 07, 2009
Hawtness, thanks for the tip!
# re: Signing 3rd Party Assemblies without Recompiling
Gravatar Jesse Slicer
Oct 22, 2009
Here's the process wrapped up in a batch file:

@echo off
if "%1"=="" goto end
if not exist %1 goto end
set SDK="C:\Program Files\Microsoft SDKs\Windows\v7.0\bin"
set FRAMEWORK="%windir%\Microsoft.NET\Framework\v2.0.50727"
echo Renaming original DLL...
move %1 %1.unsigned
echo Disassembling renamed original DLL...
pushd %~dp0
cd %SDK%
.\ildasm.exe %1.unsigned /out:%~dpn1.il
echo Generating new strong name key...
.\sn.exe -k %~dpn1.snk > nul:
echo Reassembling and signing with strong name key...
cd %FRAMEWORK%
.\ilasm.exe %~dpn1.il /dll /key=%~dpn1.snk /quiet
popd
echo Deleting intermediate disassembly and strong name key...
del %~dpn1.il
del %~dpn1.snk
echo Done!
:end
Comments have been closed on this topic.