---
title: "给第三方dll加上强命名的方法[C#]"
author: "DJ阿布"
date: "2011-09-14T19:24:29Z"
tags: []
categories: ["编程语言"]
slug: "dll-c"
draft: false
lastmod: "2011-09-14T19:25:00Z"
id: 1171991
url: "https://itchen.iteye.com/blog/1171991"
---

在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

 

 

　　这些工具都在哪里？（如果直接在命令行下执行的话，可能需要将下面的路径加入到path里）

　　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