如何使一个你没有源代码的DLL文件变为强命名的(Strong Name)

来源:互联网 发布:硬盘检测软件 编辑:程序博客网 时间:2024/05/01 21:15

有时候你会需要一个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.

原创粉丝点击