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

3

11

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!

Cyclamate answered 27/12, 2021 at 18:55 Comment(9)
From learn.microsoft.com/en-gb/dotnet/standard/assembly/strong-named: "For .NET Core and .NET 5+, strong-named assemblies do not provide material benefits. The runtime never validates the strong-name signature, nor does it use the strong-name for assembly binding." VS2022 still has the 'New' option for signing a .NET Framework assembly, so evidently you are attempting to use strong naming with a. NET Core/.NET 5+ project. Is there a reason why? What benefits are you hoping to get from it?Nuclide
So please show me the "NEW" option, I can't find it. strong name is needed to test internal and protected classesCyclamate
Can you use the sn.exe tool with the -k option to generate a new keypair (learn.microsoft.com/en-us/dotnet/framework/tools/…)? You'll need to run this from an elevated VS2022 Developer Command Prompt or PowerShell window.Nuclide
@LukeWoodward Thanks but I Know about it... you did not reed my question and did not see imagesCyclamate
If you know about sn.exe, then your question only concerns why the option to create a new signing key for a .NET Core/.NET 5+ assembly has been removed from Visual Studio 2022. I've seen your images, and I have run VS2022 myself and seen that the option you are looking for is indeed not there. Why it is not there is a question for the Visual Studio team, so you might like to try asking it at developercommunity.visualstudio.com/… instead.Nuclide
Ok, I asked (for you) see: github.com/dotnet/docs/issues/27695Wideangle
@Wideangle can you please ask this question also ( #70549946 ). I've already asked here ( developercommunity2.visualstudio.com/t/… ) but reaction on your question is faster :)Cyclamate
Reaction was faster because of 2 things. 1) this question will be solved (probably) by changing some docs. 2) Your 'other' problem is way more difficult, and seems to be an existing problem in older versions tooo..... 😉 (so, more work to fix)Wideangle
@LukeWoodward In my case, I need it for a .NET Standard 2.0 project which is consumed by .NET Framework 4.8.1, so there are legitimate uses for this feature even today.Isolde
R
1

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.

Rauwolfia answered 29/3, 2024 at 13:25 Comment(2)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewIndestructible
In the end I thought, what the hell, I just used my other .Net projects that user older framework that HAS the "New" feature in GUI and made a key! Then I just moved that PFX key to the .NET8 project. Sorted.Ernieernst
D
-1

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

Demoiselle answered 10/5, 2023 at 19:34 Comment(0)
W
-2
  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

Whitehot answered 9/3, 2023 at 5:51 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.