Creating new key file to strongly name an assembly does not work in visual studio 2022

4.3k views Asked by At

I'm using Visual Studio 2022, v17.0.4. I want to create new key for my assembly to strongly name it. According to documentation: "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".Docs

Can't find NEW button. here is an image 1

In old Visual studio it was quite easy but in new VS2022 can't find NEW button. here is an image 2

Please help!

3

There are 3 answers

0
blue On
  1. Create new key "mykey.pfx" with password from choose a strong name key file as above

  2. add strong name to your key file using developer command prompt:

sn /k "D:\Projects\mykey.pfx"

  1. build the solution. If you got an error "Cannot import the keyfile.. VS_KEY_xxxx container", install the strong name certificate to the CSP manually:

sn -i "D:\Projects\mykey.pfx" VS_KEY_xxxx

where "VS_KEY_xxxx" same as container you got in the error

0
Michael Blackburn On

Here is the MSFT documentation on creating new key files. Kind of annoying they removed this being one-click from within the UI, but I think the idea is to have people understand they are creating a self-signed certificate, and hopefully have them start to use certificates that are actually within a traceable certification authority. https://learn.microsoft.com/en-us/dotnet/standard/assembly/sign-strong-name

2
Aaron Biggs On

I was having an issue where using VS 2022, there was an option to check to Sign the assembly, however, I could only specify a Strong name key file, but not an option for "New" to create one, so using the command below, and then providing the path to the file allowed me to finally get a strongly named assembly.

Using sn.exe tool with the sn -k {assemblyName}.snk option in CMD to generate a new keypair as mentioned in Luke's comment on the initial post worked for me.