1

I installed the key pair into the key container. I am then able to build. If I restart the computer, then I get the error again.

   (ResolveKeySource target) -> 
     C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3222,5): error MSB3325: Cannot import the following key file: jmr-Digicert-2020-NoChain.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_17C40AADFD2DB0A9 [C:\Source\RsyncNet\NetSync.csproj]
     C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3222,5): error MSB3321: Importing key file "jmr-Digicert-2020-NoChain.pfx" was canceled. [C:\Source\RsyncNet\NetSync.csproj]

The solution, at least until I restart the computer, is to open an administrative command prompt and enter these commands:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\x64\sn.exe" -d VS_KEY_XXXXXXXXXXXXXXXXX
"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\x64\sn.exe" -i "C:\Documents\Signing\mycert.pfx" VS_KEY_XXXXXXXXXXXXXXXXX

The first command deletes the existing key, required, as it is there, while the second line adds the key. I get prompted to enter the password. After that the solution builds.

FYI: -i option: Install key pair from <infile> into a key container named <container>.

The Visual Studio version makes no difference, as I had the same problem with VS2017.

Thoughts?

Sarah Weinberger
  • 15,041
  • 25
  • 83
  • 130
  • What is the kind of key container? Also, can you provide the related code about your question? I find the similar solution [How to Import a Public/Private key pair into RSA Key Container](https://social.msdn.microsoft.com/Forums/vstudio/en-US/52748e61-6dc3-4730-bcf3-4eeb4d7adedc/how-to-import-a-publicprivate-key-pair-into-rsa-key-container?forum=netfxbcl) may help you. – Jack J Jun Mar 16 '20 at 02:01
  • @JackJJun-MSFTn To the best of my knowledge, there is no code, just a VS2017/9 msbuild thing. I build the projects from the command line. The referenced link implies crypto or code that I did. I do not use crypto or did anything. The keys change from time to time. On a given build there are two different keys. There used to be a different set of two. Besides, even if I did something, the solution is to import the keys, which I did. My complaint is why does that disappear after a reboot. I am not sure about logout/in. If I were more curious, another question is what are these keys. – Sarah Weinberger Mar 16 '20 at 14:20
  • try to run [Developer Command Prompt for visual studio](https://learn.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs) as administrator and then use `sn.exe` to do the same steps again. Besides, re-import the pfx file into Visual Studio. – Mr Qian Mar 18 '20 at 07:02

0 Answers0