/KEYFILE (Specify Key or Key Pair to Sign an Assembly)

 

The latest version of this topic can be found at -KEYFILE (Specify Key or Key Pair to Sign an Assembly).

KEYFILE:filename

  
## Remarks  
 where:  
  
 *filename*  
 File that contains the key. Place the string in double quotation marks (" ") if it contains a space.  
  
## Remarks  
 The linker inserts the public key into the assembly manifest and then signs the final assembly with the private key. To generate a key file, type [sn -k](../Topic/Sn.exe%20\(Strong%20Name%20Tool\).md) `file` at the command line. A signed assembly is said to have a strong name.  
  
 If you compile with [/LN](../Topic/-LN%20\(Create%20MSIL%20Module\).md), the name of the key file is held in the module and incorporated into the assembly that is created when you compile an assembly that includes an explicit reference to the module, via [#using](../Topic/%23using%20Directive%20\(C++\).md), or when linking with [/ASSEMBLYMODULE](../Topic/-ASSEMBLYMODULE%20\(Add%20a%20MSIL%20Module%20to%20the%20Assembly\).md).  
  
 You can also pass your encryption information to the linker with [/KEYCONTAINER](../Topic/-KEYCONTAINER%20\(Specify%20a%20Key%20Container%20to%20Sign%20an%20Assembly\).md). Use [/DELAYSIGN](../Topic/-DELAYSIGN%20\(Partially%20Sign%20an%20Assembly\).md) if you want a partially signed assembly. See [Strong Name Assemblies (Assembly Signing) (C++/CLI)](../Topic/Strong%20Name%20Assemblies%20\(Assembly%20Signing\)%20\(C++-CLI\).md) for more information on signing an assembly.  
  
 In case both **/KEYFILE** and **/KEYCONTAINER** are specified (either by command line option or by custom attribute), the linker will first try the key container. If that succeeds, then the assembly is signed with the information in the key container. If the linker does not find the key container, it will try the file specified with /KEYFILE. If that succeeds, the assembly is signed with the information in the key file and the key information will be installed in the key container (similar to sn -i) so that on the next compilation, the key container will be valid.  
  
 Note that a key file might contain only the public key.  
  
 See [Creating and Using Strong-Named Assemblies](../Topic/Creating%20and%20Using%20Strong-Named%20Assemblies.md) for more information on signing an assembly.  
  
 Other linker options that affect assembly generation are:  
  
-  [/ASSEMBLYDEBUG](../Topic/-ASSEMBLYDEBUG%20\(Add%20DebuggableAttribute\).md)  
  
-  [/ASSEMBLYLINKRESOURCE](../Topic/-ASSEMBLYLINKRESOURCE%20\(Link%20to%20.NET%20Framework%20Resource\).md)  
  
-  [/ASSEMBLYMODULE](../Topic/-ASSEMBLYMODULE%20\(Add%20a%20MSIL%20Module%20to%20the%20Assembly\).md)  
  
-  [/ASSEMBLYRESOURCE](../Topic/-ASSEMBLYRESOURCE%20\(Embed%20a%20Managed%20Resource\).md)  
  
-  [/NOASSEMBLY](../Topic/-NOASSEMBLY%20\(Create%20a%20MSIL%20Module\).md)  
  
### To set this linker option in the Visual Studio development environment  
  
1.  Open the project's **Property Pages** dialog box. For details, see [Setting Visual C++ Project Properties](../Topic/Working%20with%20Project%20Properties.md).  
  
2.  Click the **Linker** folder.  
  
3.  Click the **Command Line** property page.  
  
4.  Type the option into the **Additional Options** box.  
  
### To set this linker option programmatically  
  
-  See [AdditionalOptions](assetId:///P:Microsoft.VisualStudio.VCProjectEngine.VCLinkerTool.AdditionalOptions?qualifyHint=False&autoUpgrade=True).  
  
## See Also  
 [Setting Linker Options](../Topic/Setting%20Linker%20Options.md)   
 [Linker Options](../Topic/Linker%20Options.md)