Search code examples
msbuildcode-signingtfsbuild

Signing assemblies with PFX files in MSBuild, Team Build, and TFS


I get this error when trying to build a project using Team Build (MSBuild) on TFS 2010:


C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (1970):
Cannot import the following key file: CCC.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_C00C673BBB353901

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (1970):
Importing key file "CCC.pfx" was canceled.


It all builds OK in Visual Studio 2010. The assembly is signed with a PFX file. Usually in Visual Studio we are prompted for the password the first time we build, but then never again...

I've tried running:

sn -i companyname.pfx VS_KEY_3E185446540E7F7A 

as other replies as suggested in Stack Overflow question Cannot import the keyfile 'blah.pfx' - error 'The keyfile may be password protected'. I've tried importing into the personal certificate store as suggested in Stack Overflow question Using MSBuild to sign ClickOnce or assembly results in error MSB3321. But all to no avail, still the same error.

How do I do it? Do I have to somehow add the certificate to the Windows account the build service runs under or something like that?

Alternatively, how do I make the build done in Team Build not use signing? I just want to check it compiles and run the unit tests. I don't need signing for that.


Solution

  • What finally fixed it for me was making the account under which TFS Build service runs an administrator on the local machine.

    Don't know though if any of the other stuff I was trying before also needs to be done to get it working. But before it was admin it didn't work after it became admin it worked.