error MSB3325: Cannot import the following key file, restart issue - visual-studio

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?

Related

Teamcity: error MSB3147: Could not find required file 'setup.bin'

C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.target
error MSB3147: Could not find required file 'setup.bin' in ... folder
I have seen there are similar messages during the time frame of last upgrade of VS for 2012.
I did not find the registry keys on the build server as mentioned in other posts i.e. Could not find required file 'setup.bin'
I appreciate your help.
Teamcity: error MSB3147: Could not find required file 'setup.bin'
According to this blog entry the bootstrapper files are installed during the .NET Framework SDK/Visual Studio IDE install. It also shows the registry entries that are searched to look for the bootstrapper directory.
If one computer that does not have .Net Framework SDK/Visual Studio IDE installed(such as, build server), none of the registry key would be set.
I did not find the registry keys on the build server as mentioned.
You can install .Net Framework SDK/Visual Studio IDE on the build server to get this registry key. If you don not want to install them, you could manually set it up by following steps:
Copy the whole C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK folder from the local machine with Visual Studio IDE installed to the server.
creating the 14.0 registry key and adding the value:
For 86bits:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\GenericBootstrapper\14.0]
"Path"="C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper"
For 64 bits:
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\GenericBootstrapper\14.0]
"Path"="C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper"
Note: Visual Studio must be restarted.
I don't have SDK installed on the server. I have updated the .csproj with
<PropertyGroup>
...
<BootstrapperEnabled>false</BootstrapperEnabled>
</PropertyGroup>
That fixed the build.

Can't update Visual Studio 2017 RC

I'm trying to update Visual Studio 2017 RC from 15.0.25909.2 to 15.0.25914.0 and when I hit Update button it throws following error
Path to vsix file 'update' is invalid or you don't have required access permissions. Please check the path is valid and you have required access permissions.
Usage: VSIXInstaller.exe [/quiet] ...
...
I ran it as Administrator unfortunately same issue occurs.
Recorded Screen-cast is here
Thanks to #panagiotis-kanavos I did be able to solve the issue. For those who may hit the same wall, here is the steps I followed.
You need to locate Visual Studio Installer which is not in Start Menu!. You may find it at C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe
Once you run it, click on Update button.
It will probably give you errors like this
[232c:0020][2016-12-09T09:31:36] VSIX installer does not exist at 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VSIXInstaller.exe'.
[232c:0020][2016-12-09T09:31:36] Package '...' failed to uninstall. Return code: 2
Check the path and make sure VSIXInstaller.exe is there
Once again, click on Update button.
this time, it will throw a different error and if you open the log file that upgrade process provides, it should have full command details which is/are failing
🚨 WARNING 🚨 following code was in "my" log file and I placed it here "only for demonstration purpose", do not use it directly, check your log file to get correct failing errors
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VSIXInstaller.exe" /q /s /admin /appidinstallpath:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe" /logFile:"C:\Users\ciler\AppData\Local\Temp\dd_setup_20161209094800_001_GitHub.VisualStudio.log" /skuName:Enterprise /skuVersion:15.0.25928.0 /appidname:displayName /uninstall:c3d3dc68-c977-411f-b3e8-03b0dccf7dfc
Run that command in your Command Prompt and make sure you change the /logfile: filename in order to eliminate overwriting the existing one.

Gacutil not installed by default in VisualStudio

I am unable to add an assembly into GAC. Please assist in getting it work. I ran following command in VisualStudio13 CMD
gacutil /i “<C:\Program Files\ibm\IBM DATA SERVER DRIVER>\bin\netf40_32\IBM.Data.DB2.Entity.dll”
Error Message:
Command "gacutil" is not valid.
Also, i checked there is also no gacutil.exe file on path
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0
Tools
But when i access the path there is no gacutil file as shown:
The issue was Windows Explorer path(C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe) had no "gacutil.exe". Accessing the same path through cmd listed down "gacutil.exe" as present.
Thus, instead of just giving command gacutil-i to add an assembly in cache, i gave full path
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0Tools\gacutil.exe -i
Don't trust windows explorer. Trust command credits# Sir Conrad Frix-Comments
You can either drag-drop the .dll into c:\windows\assembly folder or check C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\x64 for gacutil as its part of .net framework, not your IDE. Hope it helps!

Makecert.exe error

I am trying to use Makecert.exe to create a signing certificate that I can use with our internal VS.NET applications, to be deployed using Clickonce on our local network
I have been following the MSDN guide MSDN: Certificate Expiration in ClickOnce Deployment
so I tried the below:
C:\Program Files (x86)\Microsoft Visual Studio 12.0>Makecert -sv DMTeam.pvk
-n "CN=DMTeam" DMTeam.cer -b 03/04/2015 -e 12/31/2020
in order to have a certificate for our applications
When I run the above command using the VS command prompt, I get the below error:
Error: Unable to create file for the subject ('DMTeam.pvk')
Error: Can't create the key of the subject ('DMTeam.pvk')
Failed
so what am doing wrong?
The key is to run the command prompt with Administrator privileges.
I did something very similar, though I wrote the pvk and cer files to my c:\Temp folder:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin>MakeCert –sv C:\Temp\DMTeam.pvk –n “CN=DMTeam” c:\Temp\DMTeam.cer –b 03/04/2015 –e 12/31/2020 -r
Don't forget the "-r" option as it will "Create a self-signed certificate"! Without it the project will not build when you use the created pfx file.
I ran this under the VS2012 x86 Native Tools Command Prompt (with Run as Administrator) and it works just fine. Run without Administrative privileges and then it fails.
Then to create the pfx file do the following:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin>pvk2pfx –pvk C:\Temp\DMTeam.pvk –spc C:\Temp\DMTeam.cer –pfx –po PasswordForPFXFile
Here are some good references:
See section: Test Certificates, MakeCert, RenewCert, and The Big Workaround
https://msdn.microsoft.com/en-us/library/ff369721.aspx
https://msdn.microsoft.com/en-us/library/bfsktky3(v=vs.110).aspx
ClickOnce signer's certificate not valid for signing when using makecer/pvk2pfx
My ClickOnce app now builds fine in Visual Studio 2013.

Visual Studio 2010 Assembly Signing: An attempt was made to reference a token that does not exist

I'm trying to sign an assembly in Visual Studio 2010 with our PFX file, after I enter the password for the private key I get "An attempt was made to reference a token that does not exist"
Running Visual Studio as Administrator fixed this issue for me.
I have the same problem. Just use signtool from the Visual Studio command prompt instead. Sometimes signtool will claim your password is invalid, but usually after a couple of tries it starts working for me.
signtool.exe sign /f YOURCERT.pfx /p YOURPASSWORD YOURTARGET.exe
If you want Visual Studio to automatically sign the files and work with ClickOnce, this is what I had to do:
Get a copy of OpenSSL. It is available for Windows. Or use a Linux box as they all pretty much all have it.
Run the following to export to a key file:
openssl pkcs12 -in certfile.pfx -out backupcertfile.key
openssl pkcs12 -export -out certfiletosignwith.pfx -keysig -in backupcertfile.key
Then in the project properties you can use the PFX file.
This is what worked for me.
First try to build your project with the Key signing option enabled for your project. The build will fail, goto the 'Output' window and you'll see an error like:
Error 1 Cannot import the following key file: MyKey.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_7B9423FE45F4DBEB Project.SomeName
Save the Key Store name (e.g. VS_KEY_7B9423FE45F4DBEB), you will need this later.
Now follow these steps:
Import the digital certificate key (PFX) in the Windows Certificate Store. Double click the PFX key in Windows Explorer and install/import it into your key store (I actually imported it into the trusted root certificates store by selecting manually choose store).
Start Visual Studio 2010 as regular user (I don't face this key signing issue as an Administrator, but I want to debug my apps as a user) (keep it open through this entire process)
From the Start Menu open the Visual Studio Command Prompt (2010) shortcut (x64 if you on a x64 machine) AS AN ADMINISTRATOR (right click on the Visual Studio 2010 Command Prompt shortcut and select run as Administrator). This should open an administrative command prompt with the Visual Studio environment setup. (not a regular command prompt)
In the command prompt, enter sn -d VS_KEY_xxxx with Key Store name from error message you saved at the beginning
Then enter sn -i xxx.pfx VS_KEY_xxxx, enter password when prompted, xxx.pfx if your digital certificate
Go back to Visual Studio and rebuild your project

Resources