Tuesday, February 9, 2016

Quick fix for a small issue while upgrading project to Visual Studio 2010

Here’s another quick fix for a small issue you may encounter when upgrading your project to Visual Studio 2010.  You may find that the import works okay, but when you go to compile, you get the following error message:
Cannot import the following key file: keyfile.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_0123456701234567
The cause of the error is exactly as Visual Studio described: it can’t open the key file it needs to access because the key file is password protected.  The suggested fix, however, is not likely to set you on the right path.  In fact, Visual Studio should really just fix this itself.  In previous versions, it would.  Remember you’d occasionally get a password prompt when opening a project for the first time?
Well, all we need to do to fix this is trigger Visual Studio to ask you for the password.  Then, it will do its thing and you’ll be set.  Try this:
1.                 Open Project Properties. 
2.                 Click on the Signing section. 



3.                 Where it says ‘Choose a strong name key file:’, reselect the current value from the drop-down box: 

 4.                 Visual Studio will now prompt you for the password.  Enter it.
 
5.                 You might get another error message:

”An attempt was made to reference a token that does not exist”

If so, just ignore it. 
6.                 Click the ‘Change Password” button:  
7.                 Enter the original password in all three boxes and click OK. If you’d like to change your password (or if your old password doesn’t meet complexity requirements), you can do so now. 
8.                 Repeat for each key file in your project. 
9.                 Save your project and do a rebuild.

Of course, there are less empirical ways of solving this, but they involve using the signtool.exe application and messing around with the certificate store.  This might not be the most impressive way of solving this problem, but it seems to work.

No comments:

Post a Comment