Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 628
MikeG Avatar asked Oct 26 '10 15:10

MikeG


People also ask

Can I use MSBuild without Visual Studio?

To install MSBuild on a system that doesn't have Visual Studio, go to Build Tools for Visual Studio 2019, or install the . NET SDK. If you have Visual Studio, then you already have MSBuild installed. With Visual Studio 2022, it's installed under the Visual Studio installation folder.

Is Visual Studio using MSBuild?

Visual Studio uses MSBuild, but MSBuild doesn't depend on Visual Studio. By invoking msbuild.exe or dotnet build on your project or solution file, you can orchestrate and build products in environments where Visual Studio isn't installed. Visual Studio uses MSBuild to load and build managed projects.

How use MSBuild command line?

To enable msbuild in Command Prompt, you simply have to add the directory of the msbuild.exe install on your machine to the PATH environment variable. You can access the environment variables by: Right clicking on Computer. Click Properties.

How do you make a solution with MSBuild?

To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.


2 Answers

You need to adapt this answer to your specific. Something like:

sn -i companyname.pfx VS_KEY_C00C673BBB353901
like image 56
heavyd Avatar answered Oct 09 '22 17:10

heavyd


What I did is not that elegant, but works: log in as the user that runs msbuild on the build machine, manually invoke msbuild, and then type in the password when prompted. It'll now be saved in that user's certificate store, and now the builds can run unattended.

like image 44
gregmac Avatar answered Oct 09 '22 17:10

gregmac