How do I automate code signing in Visual Studio?

There are several methods of signing with Visual Studio, depending on exactly what you want to do.

For signing the compiled EXE, a post-build step is the easiest route:

In order to get a signature automatically applied to your EXE (or DLL) when you compile/build, you need to call a signing utility like SignTool.exe as a post-build step.

Microsoft has a good tutorial on that, view it here:

Note: If you want strong name signing (at the assembly level), you'll need to re-import your certificate. Follow the procedure to export it to a file from When you export the certificate be sure to NOT check any other options other than yes export with private key and then re-import the certificate in to the CSP with the command:

certutil -importPFX -user 'path to pfx' AT_SIGNATURE

Note: Use this command to help find process certutil -importPFX -?

This sets the KeySpec=2 flag (AT_SIGNATURE).

You can then re-export THAT certificate and use it directly with Visual Studio.