28

The reason I want to sign the dll is because I want to add it to the Global Assembly Cache. The assembly is a css parsing engine written in Java and ported to J#. I use VS2008 so I can't make J# projects. It doesn't have a strong name key assigned to it and I have no idea how to do it now that it's built.

Anyone have any ideas?

  • 1
    I have to ask - why do you want to install it in the GAC? Even with with assemblies used with by multiple websites on the same server, we've gotten into the (perhaps questionable) habit of letting each site/application keep its own copy in its bin folder. This ensures that the web application always has the version it was built with and expects, and makes deployment and rollbacks simple as there are no dependencies that live outside of the web folder hierarchy. – 3Dave Sep 04 '09 at 15:36
  • Yeah but whatever way I have my permissions wired my Website Deployment Project gives me a warning every time I compile saying that it doesn't have permissions to move the dll. It gives the same warning on TFS Build. I'm trying to get rid of all my warnings. FXCop included. –  Sep 04 '09 at 16:30

5 Answers5

49

After a little searching, I found this post that explains one way of doing it.

Exerpt:

From a VS.NET command prompt, enter the following:

  1. Generate a KeyFile: sn -k keyPair.snk
  2. Obtain the MSIL for the provided assembly: ildasm providedAssembly.dll /out:providedAssembly.il
  3. Rename/move the original assembly: ren providedAssembly.dll providedAssembly.dll.orig
  4. Create a new assembly from the MSIL output and your assembly KeyFile: ilasm providedAssembly.il /dll /key=keyPair.snk
Behzad Ebrahimi
  • 992
  • 1
  • 16
  • 28
PJ8
  • 1,278
  • 10
  • 15
  • I've tried getting that to work before and was unable, can you explain how –  Sep 04 '09 at 16:39
  • 5
    Link is broken. Here's an alternative source for (presumably) the same information, found via Google: http://www.geekzilla.co.uk/ViewCE64BEF3-51A6-4F1C-90C9-6A76B015C9FB.htm – RenniePet Dec 22 '12 at 20:34
  • @PJ8 Still does not work to me... now i receive following runtime error `Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations` – Simone Nov 05 '14 at 10:31
21

Step 1: Dis-assemble the assembly

ildasm myTest.dll /out:myTest.il 

Step 2: Re-Assemble using your strong-name key

ilasm myTest.il /res:myTest.res /dll /key:myTest.snk /out:myTestSN.dll 

For verification you can use following command:

sn -vf myTestSN.dll

Hope this helps!

Jeremy E
  • 3,704
  • 2
  • 28
  • 46
3

This link also shows how to do it, including when one of the 3rd party assemblies you're signing has a reference to another unsigned assembly that you're signing:

http://buffered.io/posts/net-fu-signing-an-unsigned-assembly-without-delay-signing

Edit: sorry, link is busted.

Wes
  • 1,059
  • 13
  • 18
  • Broken Link! Alternative: https://github.com/OJ/buffered.io-hugo/blob/master/content/post/2008-07-09-net-fu-signing-an-unsigned-assembly-without-delay-signing.markdown – Patrick Sep 13 '17 at 13:23
2

Thx especially PJ8 for posting an answer 8 years ago that still saved me today. "My" assembly needed to go in the GAC but was dependent on SQLite-pcl-net which as of version 1.3.1 is not strong-named although it is now dependent on the strong-named SQLitePCLRaw.bundle_green. So I had to sign SQLite-pcl-net in order to sign my own assembly in other words. I ended up with a cradle-to-grave .bat file consolidated from info in this post and a few other places I traveled today. The "pros" are 1. that this .bat runs in the location of the assembly that you want to sign 2. shows at least a hint as to where the three tools might be located on a dev machine. 3. shows all the steps in order. The "con" of course is that your mileage may vary as to where ildasm, ilasm and sn are actually located on your particular PC. Anyway cheers.

REM Create a new, random key pair
"c:\program files (x86)\microsoft sdks\windows\v8.1a\bin\NETFX 4.5.1 Tools\sn" -k SQLite-net.snk
REM Store the key in the container MySQLiteKeys in the strong name Cryptographic Services Provider (CSP).
"c:\program files (x86)\microsoft sdks\windows\v8.1a\bin\NETFX 4.5.1 Tools\sn" -i SQLite-net.snk MySQLiteKeys
REM Disassemble to Intermediate Language
"c:\program files (x86)\microsoft sdks\windows\v8.1a\bin\NETFX 4.5.1 Tools\ildasm" SQLite-net.dll /out:SQLite-net.il
REM Rename original file
ren SQLite-net.dll SQLite-net.dll.orig
REM Reassemble to a strong-named version
"c:\Windows\Microsoft.NET\Framework\v2.0.50727\ilasm" SQLite-net.il /dll /key=SQLite-net.snk /out:SQLite-net.dll 
REM Verify the assembly 
"c:\program files (x86)\microsoft sdks\windows\v8.1a\bin\NETFX 4.5.1 Tools\sn" -v SQLite-net.dll
REM Deletes MySQLiteKeys from the default CSP
"c:\program files (x86)\microsoft sdks\windows\v8.1a\bin\NETFX 4.5.1 Tools\sn" -d MySQLiteKeys
REM View results 
pause
IVSoftware
  • 5,732
  • 2
  • 12
  • 23
  • (Hey thanks in advance for the style editing. I tried really hard to find the correct presentation format but I think I missed.) – IVSoftware Apr 06 '17 at 22:45
1

The Strong Name tool can re-sign an existing assembly, using the -R option. However, from what I understand, the assembly has to be previously signed or delay-signed... not sure you can use it with an unsigned assembly, but you can give it a try

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758