Skip to content

Commit 6040994

Browse files
authored
Fix navigation to VS Strong naming options (#27735)
1 parent 37ab24e commit 6040994

File tree

2 files changed

+52
-57
lines changed

2 files changed

+52
-57
lines changed
22 KB
Loading

docs/standard/assembly/sign-strong-name.md

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,75 @@
11
---
22
title: "How to: Sign an assembly with a strong name"
33
description: This article shows you how to sign a .NET assembly with a strong name by using the Signing tab, the Assembly Linker, assembly attributes, or compiler options.
4-
ms.date: "08/20/2019"
5-
helpviewer_keywords:
4+
ms.date: 01/05/2022
5+
helpviewer_keywords:
66
- "strong-named assemblies, signing with strong names"
77
- "signing assemblies"
88
- "assemblies [.NET], signing"
99
- "assemblies [.NET], strong-named"
1010
ms.topic: how-to
11-
dev_langs:
11+
dev_langs:
1212
- "csharp"
1313
- "vb"
1414
- "cpp"
1515
---
16+
1617
# How to: Sign an assembly with a strong name
1718

1819
> [!NOTE]
1920
> Although .NET Core supports strong-named assemblies, and all assemblies in the .NET Core library are signed, the majority of third-party assemblies do not need strong names. For more information, see [Strong Name Signing](https://github.com/dotnet/runtime/blob/main/docs/project/strong-name-signing.md) on GitHub.
2021
21-
There are a number of ways to sign an assembly with a strong name:
22-
23-
- By using the **Signing** tab in a project's **Properties** dialog box in Visual Studio. This is the easiest and most convenient way to sign an assembly with a strong name.
24-
25-
- By using the [Assembly Linker (Al.exe)](../../framework/tools/al-exe-assembly-linker.md) to link a .NET Framework code module (a *.netmodule* file) with a key file.
26-
27-
- By using assembly attributes to insert the strong name information into your code. You can use either the <xref:System.Reflection.AssemblyKeyFileAttribute> or the <xref:System.Reflection.AssemblyKeyNameAttribute> attribute, depending on where the key file to be used is located.
28-
29-
- By using compiler options.
30-
31-
You must have a cryptographic key pair to sign an assembly with a strong name. For more information about creating a key pair, see [How to: Create a public-private key pair](create-public-private-key-pair.md).
32-
33-
## Create and sign an assembly with a strong name by using Visual Studio
34-
35-
1. In **Solution Explorer**, open the shortcut menu for the project, and then choose **Properties**.
36-
37-
2. Choose the **Signing** tab.
38-
39-
3. Select the **Sign the assembly** box.
40-
41-
4. In the **Choose a strong name key file** box, choose **Browse**, and then navigate to the key file. To create a new key file, choose **New** and enter its name in the **Create Strong Name Key** dialog box.
42-
22+
There are a number of ways to sign an assembly with a strong name:
23+
24+
- By using the **Signing** tab in a project's **Properties** dialog box in Visual Studio. This is the easiest and most convenient way to sign an assembly with a strong name.
25+
- By using the [Assembly Linker (Al.exe)](../../framework/tools/al-exe-assembly-linker.md) to link a .NET Framework code module (a _.netmodule_ file) with a key file.
26+
- By using assembly attributes to insert the strong name information into your code. You can use either the <xref:System.Reflection.AssemblyKeyFileAttribute> or the <xref:System.Reflection.AssemblyKeyNameAttribute> attribute, depending on where the key file to be used is located.
27+
- By using compiler options.
28+
29+
You must have a cryptographic key pair to sign an assembly with a strong name. For more information about creating a key pair, see [How to: Create a public-private key pair](create-public-private-key-pair.md).
30+
31+
## Create and sign an assembly with a strong name by using Visual Studio
32+
33+
1. In **Solution Explorer**, open the shortcut menu for the project, and then choose **Properties**.
34+
1. Under the **Build** tab you'll find a **Strong naming** node.
35+
1. Select the **Sign the assembly** checkbox, which expands the options.
36+
1. Select the **Browse** button to choose a **Strong name key file** path.
37+
4338
> [!NOTE]
44-
> In order to [delay sign an assembly](delay-sign.md), choose a public key file.
45-
46-
### Create and sign an assembly with a strong name by using the Assembly Linker
47-
48-
Open [Visual Studio Developer Command Prompt or Visual Studio Developer PowerShell](/visualstudio/ide/reference/command-prompt-powershell), and enter the following command:
39+
> In order to [delay sign an assembly](delay-sign.md), choose a public key file.
40+
41+
:::image type="content" source="./media/strong-naming-properties.png" alt-text="Visual Studio 2022: Project properties, Build / Strong naming section.":::
4942

50-
**al** **/out:**\<*assemblyName*> *\<moduleName>* **/keyfile:**\<*keyfileName*>
43+
### Create and sign an assembly with a strong name by using the Assembly Linker
5144

52-
Where:
45+
Open [Visual Studio Developer Command Prompt or Visual Studio Developer PowerShell](/visualstudio/ide/reference/command-prompt-powershell), and enter the following command:
5346

54-
- *assemblyName* is the name of the strongly signed assembly (a *.dll* or *.exe* file) that Assembly Linker will emit.
55-
56-
- *moduleName* is the name of a .NET Framework code module (a *.netmodule* file) that includes one or more types. You can create a *.netmodule* file by compiling your code with the `/target:module` switch in C# or Visual Basic.
57-
58-
- *keyfileName* is the name of the container or file that contains the key pair. Assembly Linker interprets a relative path in relation to the current directory.
47+
**al** **/out:**\<_assemblyName_> _\<moduleName>_ **/keyfile:**\<_keyfileName_>
5948

60-
The following example signs the assembly *MyAssembly.dll* with a strong name by using the key file *sgKey.snk*.
49+
Where:
50+
51+
- _assemblyName_ is the name of the strongly signed assembly (a _.dll_ or _.exe_ file) that Assembly Linker will emit.
52+
- _moduleName_ is the name of a .NET Framework code module (a _.netmodule_ file) that includes one or more types. You can create a _.netmodule_ file by compiling your code with the `/target:module` switch in C# or Visual Basic.
53+
- _keyfileName_ is the name of the container or file that contains the key pair. Assembly Linker interprets a relative path in relation to the current directory.
54+
55+
The following example signs the assembly _MyAssembly.dll_ with a strong name by using the key file _sgKey.snk_.
6156

6257
```console
63-
al /out:MyAssembly.dll MyModule.netmodule /keyfile:sgKey.snk
64-
```
65-
66-
For more information about this tool, see [Assembly Linker](../../framework/tools/al-exe-assembly-linker.md).
67-
68-
## Sign an assembly with a strong name by using attributes
69-
70-
1. Add the <xref:System.Reflection.AssemblyKeyFileAttribute?displayProperty=nameWithType> or <xref:System.Reflection.AssemblyKeyNameAttribute> attribute to your source code file, and specify the name of the file or container that contains the key pair to use when signing the assembly with a strong name.
58+
al /out:MyAssembly.dll MyModule.netmodule /keyfile:sgKey.snk
59+
```
60+
61+
For more information about this tool, see [Assembly Linker](../../framework/tools/al-exe-assembly-linker.md).
7162

72-
2. Compile the source code file normally.
63+
## Sign an assembly with a strong name by using attributes
7364

74-
> [!NOTE]
75-
> The C# and Visual Basic compilers issue compiler warnings (CS1699 and BC41008, respectively) when they encounter the <xref:System.Reflection.AssemblyKeyFileAttribute> or <xref:System.Reflection.AssemblyKeyNameAttribute> attribute in source code. You can ignore the warnings.
65+
1. Add the <xref:System.Reflection.AssemblyKeyFileAttribute?displayProperty=nameWithType> or <xref:System.Reflection.AssemblyKeyNameAttribute> attribute to your source code file, and specify the name of the file or container that contains the key pair to use when signing the assembly with a strong name.
7666

77-
The following example uses the <xref:System.Reflection.AssemblyKeyFileAttribute> attribute with a key file called *keyfile.snk*, which is located in the directory where the assembly is compiled.
67+
2. Compile the source code file normally.
68+
69+
> [!NOTE]
70+
> The C# and Visual Basic compilers issue compiler warnings (CS1699 and BC41008, respectively) when they encounter the <xref:System.Reflection.AssemblyKeyFileAttribute> or <xref:System.Reflection.AssemblyKeyNameAttribute> attribute in source code. You can ignore the warnings.
71+
72+
The following example uses the <xref:System.Reflection.AssemblyKeyFileAttribute> attribute with a key file called _keyfile.snk_, which is located in the directory where the assembly is compiled.
7873

7974
```cpp
8075
[assembly:AssemblyKeyFileAttribute("keyfile.snk")];
@@ -88,19 +83,19 @@ The following example uses the <xref:System.Reflection.AssemblyKeyFileAttribute>
8883
<Assembly:AssemblyKeyFileAttribute("keyfile.snk")>
8984
```
9085

91-
You can also delay sign an assembly when compiling your source file. For more information, see [Delay-sign an assembly](delay-sign.md).
86+
You can also delay sign an assembly when compiling your source file. For more information, see [Delay-sign an assembly](delay-sign.md).
9287

93-
## Sign an assembly with a strong name by using the compiler
88+
## Sign an assembly with a strong name by using the compiler
9489

95-
Compile your source code file or files with the `/keyfile` or `/delaysign` compiler option in C# and Visual Basic, or the `/KEYFILE` or `/DELAYSIGN` linker option in C++. After the option name, add a colon and the name of the key file. When using command-line compilers, you can copy the key file to the directory that contains your source code files.
90+
Compile your source code file or files with the `/keyfile` or `/delaysign` compiler option in C# and Visual Basic, or the `/KEYFILE` or `/DELAYSIGN` linker option in C++. After the option name, add a colon and the name of the key file. When using command-line compilers, you can copy the key file to the directory that contains your source code files.
9691

97-
For information on delay signing, see [Delay-sign an assembly](delay-sign.md).
92+
For information on delay signing, see [Delay-sign an assembly](delay-sign.md).
9893

99-
The following example uses the C# compiler and signs the assembly *UtilityLibrary.dll* with a strong name by using the key file *sgKey.snk*.
94+
The following example uses the C# compiler and signs the assembly _UtilityLibrary.dll_ with a strong name by using the key file _sgKey.snk_.
10095

10196
```cmd
102-
csc /t:library UtilityLibrary.cs /keyfile:sgKey.snk
103-
```
97+
csc /t:library UtilityLibrary.cs /keyfile:sgKey.snk
98+
```
10499

105100
## See also
106101

0 commit comments

Comments
 (0)