Welcome to MSDN Blogs Sign in | Join | Help

How To: Specify strong name signing for your assemblies on the command line

This question came across the internal MSBuild discussion alias today:

My development team uses project files on their desktop for development, but we build the final assemblies in our build lab. How can we strong-name sign the files in our build lab using MSBuild, while still allowing the same project files to be used on developer machines?

My initial response was to simply edit the assemblyinfo.cs files and specify the key file information there. This doesn't work, however, since the developers don't have access to the key used for signing. An alternative, though hacky solution, would be to use the Exec task to call out to sn.exe and sign the files in the AfterBuild target. However, this really is a hacked up way to do it, so we dug around for a better way.

It turns out that the signing process in the Visual Studio build was done by the deployment team. We consulted with the deployment team and it turns out they accounted for this very scenario when they added their signing support into the Microsoft.Common.targets file. To do this via the command line you need to set two properties: SignAssembly and AssemblyOriginatorKeyFile. The command line would look something like this:

msbuild myapplication.sln /p:SignAssembly=true /p:AssemblyOriginatorKeyFile=mykey.snk

[ Author: Neil Enns ]

Published Monday, September 26, 2005 7:50 PM by msbuild
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Friday, November 11, 2005 11:12 AM by JohnL

# re: How To: Specify strong name signing for your assemblies on the command line

Does the .snk file need a path?
I know when the AssemblyKeyFile flag is specified, you need to add a path because the al command is executed in the bin\Debug directory
Monday, February 13, 2006 10:57 AM by Teucer's Quiver

# Delay signing and VS 2005 challenges

Thursday, June 08, 2006 3:05 PM by uow04b9@altavista.com

# re: How To: Specify strong name signing for your assemblies on the command line

ringtones free
Monday, March 24, 2008 10:26 PM by ArtInAct

# What about Password for a strong name key file?

In IDE we specify not only key file but a password as well. How to do it with MSBuild?

Wednesday, August 06, 2008 10:26 AM by tim johnson

# re: How To: Specify strong name signing for your assemblies on the command line

if anyone else is looking, here is what is needed for delay-signing:

/p:SignAssembly=true /p:AssemblyOriginatorKeyFile="mykey.snk" /p:DelaySign=true

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker