如何使一個你沒有源代碼的DLL文件變爲強命名的(Strong Name)

有時候你會需要一個DLL是強命名的,比如你想把這個文件放到GAC裏面。如果這是一個第三方的DLL,你沒有源代碼,這會是一件比較麻煩的事情。有一個方法可以解決這個問題。

在VS.NET的命名行窗口下,輸入如下的代碼。

1 ,生成一個KeyFile

sn -k keyPair.snk

2, 得到程序集的MSIL

ildasm SomeAssembly.dll /out:SomeAssembly.il

3 ,爲了避免衝突,把原來的DLL文件改名

ren SomeAssembly.dll SomeAssembly.dll.orig

4 , 使用導出的MSIL和剛創建的KeyFile生成一個新的的DLL文件。

ilasm SomeAssembly.il /dll /key= keyPair.snk

Where do these tools live

這些工具都在哪裏?

  • C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/ilasm.exe
  • C:/Program Files/Microsoft Visual Studio 8/SDK/v2.0/Bin/ildasm.exe
  • C:/Program Files/Microsoft Visual Studio 8/SDK/v2.0/Bin/sn.exe

From:http://msdn.microsoft.com/zh-cn/dd552271.aspx

 

 

Solution of the assigning the strong name to the third part DLL by using following command on visual studio command prompt.

E.g. Lets say the name of the third party DLL is myTest.dll. 
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

This code work perfectly to assign strong name.

for verification you can use following command,
sn -vf myTestSN.dll

 

If the 3rd party assembly is delay signed, you can just add it to the Skip Verification list:
SN -Vr YourAssemblyName
So CLR will no longer validate this assembly while loading it.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章