指定密钥对的密钥容器名称从而为程序集赋予强名称。Specifies a key container name for a key pair to give an assembly a strong name.




术语Term 定义Definition
container 必需。Required. 包含密钥的容器文件。Container file that contains the key. 如果文件名包含空格,则将它括在引号 ("") 内。Enclose the file name in quotation marks ("") if the name contains a space.


通过将公钥插入到程序集清单并且用私钥签名最终程序集,编译器可创建可共享的组件。The compiler creates the sharable component by inserting a public key into the assembly manifest and by signing the final assembly with the private key. 若要生成密钥文件,请在命令行键入 sn -k fileTo generate a key file, type sn -k file at the command line. -i 选项将密钥对安装到容器中。The -i option installs the key pair into a container. 有关详细信息,请参阅 Sn.exe(强名称工具)For more information, see Sn.exe (Strong Name Tool)).

如果使用 -target:module 进行编译,密钥文件的名称将保存在模块中,并在使用 -addmodule 编译程序集时包含到创建的程序集中。If you compile with -target:module, the name of the key file is held in the module and incorporated into the assembly that is created when you compile an assembly with -addmodule.

还可以将此选项指定为任何 Microsoft 中间语言 (MSIL) 模块的源代码中的自定义特性 (AssemblyKeyNameAttribute)。You can also specify this option as a custom attribute (AssemblyKeyNameAttribute) in the source code for any Microsoft intermediate language (MSIL) module.

此外,可使用 -keyfile 将加密信息传递给编译器。You can also pass your encryption information to the compiler with -keyfile. 如果需要部分签名的程序集,请使用 -delaysignUse -delaysign if you want a partially signed assembly.

有关对程序集签名的详细信息,请参阅创建和使用具有强名称的程序集See Creating and Using Strong-Named Assemblies for more information on signing an assembly.


Visual Studio 开发环境内无法使用 -keycontainer 选项;仅当从命令行编译时才可用。The -keycontainer option is not available from within the Visual Studio development environment; it is available only when compiling from the command line.


下面的代码编译源文件 Input.vb,并指定一个密钥容器。The following code compiles source file Input.vb and specifies a key container.

vbc -keycontainer:key1 input.vb  

请参阅See also