如何使一个你没有源代码的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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值