Search code examples
visual-studioclickoncecode-signing.net-4.8pfx

Visual Studio 2022: sign manifest and assembly from the same pfx file


I've a windows forms 4.8 project which is published through click once and I'd like to sign the manifest and the exe assembly. I've received a pfx and I've started by making sure that it didn't have the complete certificate chain and that it didn't have any passwords (pfx and private key) by following these instructions.

I'm able to pick the pfx file for the click once and assembly signing options without any errors:

VS 2022 Signing tab options

Despite that, I'm unable to compile the project. Whenever I try to do that, I end up getting the following errors:

error MSB3325: Cannot import the following key file: code2.pfx. 
The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_B8EEC53897B24E78

Even though the file is not password protected, I tried to install the certificate to the strong name csp with the suggested container name, I end up with a message that says that the object already exists:


sn -i code2.pfx VS_KEY_B8EEC53897B24E78

Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Enter the password for the PKCS#12 key file:
Failed to install key pair -- Object already exists.

Any clues on how to sign the manifest and main assembly with a pfx file? What am I missing?

PS: I've tried using machine and user containers (sn -m), but still getting the same error message.

Thanks


Solution

  • So, it seems like I've finally managed to get it working. After finding this post, I've regenerated the certificate with the KeySpec parameter set Signature and made sure that the pfx didn't include the complete certificate chain.

    After doing that, I didn't even need to unprotect the pfx or the private key and I was able to import the pfx directly from within VS for manifest and assembly signing.