0

Ive been trying to sign a FSharp Class library in visual studio and i am not sure what went wrong. when i select create a new strong name key file, visual studio will force restart. the below gif is a demo of me trying to sign the package.

i tried to create a snk file with in command line but i need to create a snk file with password protected given the D365 plugin require so. Any advice are appreciated!

Thanks in advance.

Henk van Boeijen
  • 7,357
  • 6
  • 32
  • 42

1 Answers1

1

In Visual Studio these kind of issues can be caused by a bad behaving extension or perhaps a corrupted project file. Disable suspected extensions and try again.

Another fix is creating an snk file using the Strong Name Utility snk.exe and adding it to the project by hand. Remember, the signing tab of your project is just a handy UI for the underlying fsproj file.

Steps:

  1. Open the developer command prompt.
  2. Type snk.exe -k mykey.snk.
  3. Open your .fsproj file and add the following lines:
  <PropertyGroup>
    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>mykey.snk</AssemblyOriginatorKeyFile>
  </PropertyGroup>
  1. Compile your project and you're done.

An alternative for step 3 is adding an assembly attribute to your project:

[<assembly:AssemblyKeyFileAttribute("mykey.snk")>]

See also How to: Create a public-private key pair - MS Docs.

Henk van Boeijen
  • 7,357
  • 6
  • 32
  • 42
  • thanks for the advice. i am just wonder if do you know how to add password to the snk when create because i dont seem to find it in the documentation. – Helicon Mar 31 '22 at 03:07
  • It is not possible to add a password using sn.exe. Instead you would need to create a _code-signing certificate_ (PFX) and _delay sign_ your assembly with that. This is typically done in a release build pipeline. ([Code signing](https://bettersolutions.com/csharp/projects/properties-signing.htm)) – Henk van Boeijen Mar 31 '22 at 07:14
  • These contributions on StackOverflow may also be helpful: [How to create a snk from pfx](https://stackoverflow.com/questions/8174229/how-to-create-a-snk-from-pfx-cer/11461474#11461474). – Henk van Boeijen Mar 31 '22 at 07:21