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: http://msdn.microsoft.com/en-us/library/ms180786%28VS.80%29.aspx

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 https://support.sectigo.com/Com_KnowledgeDetailPage?Id=kA01N000000zFK0 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.

Source: http://blogs.msdn.com/b/andrekl/archive/2008/01/08/strong-name-signing-in-visual-studio-2005-requires-keyspec-2-at-signature.aspx

and https://msdn.microsoft.com/en-us/library/br230260.aspx