You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/standard/assembly/sign-strong-name.md
+52-57Lines changed: 52 additions & 57 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,80 +1,75 @@
1
1
---
2
2
title: "How to: Sign an assembly with a strong name"
3
3
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:
6
6
- "strong-named assemblies, signing with strong names"
7
7
- "signing assemblies"
8
8
- "assemblies [.NET], signing"
9
9
- "assemblies [.NET], strong-named"
10
10
ms.topic: how-to
11
-
dev_langs:
11
+
dev_langs:
12
12
- "csharp"
13
13
- "vb"
14
14
- "cpp"
15
15
---
16
+
16
17
# How to: Sign an assembly with a strong name
17
18
18
19
> [!NOTE]
19
20
> 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.
20
21
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
+
43
38
> [!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.
### Create and sign an assembly with a strong name by using the Assembly Linker
51
44
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:
53
46
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.
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_.
61
56
62
57
```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).
71
62
72
-
2. Compile the source code file normally.
63
+
## Sign an assembly with a strong name by using attributes
73
64
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.
76
66
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.
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).
92
87
93
-
## Sign an assembly with a strong name by using the compiler
88
+
## Sign an assembly with a strong name by using the compiler
94
89
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.
96
91
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).
98
93
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_.
0 commit comments