Some people have asked how to do this in other threads, so here's a slightly modified manifest-signing functionfrom the ClickOnce Community Resource Kit which can be downloaded at
http://www.codeplex.com/smartclient/Project/FileDownload.aspx?DownloadId=5060.
Code Block
using
System.Security.Cryptography.X509Certificates;
using
Microsoft.Build.Tasks.Deployment.ManifestUtilities;
// Also needs a reference to Microsoft.Build.Tasks
public
static void SignManifest( string manifestFilePath, string certFilePath, stringpassword, string timestampUrl )
{
if ( !File.Exists( certFilePath ) )
{
throw new ArgumentException( "Invalid certificate file path" );
}
else if ( !File.Exists( manifestFilePath ) )
{
throw new ArgumentException( "Invalid manifest file path" );
}
else
{
X509Certificate2 cert;
if ( string.IsNullOrEmpty( password ) )
{
cert =
new X509Certificate2( certFilePath );
}
else
{
cert =
new X509Certificate2( certFilePath, password );
}
Uri timestampUri = null;
if ( !string.IsNullOrEmpty( timestampUrl ) )
{
timestampUri =
new Uri( timestampUrl );
}
SecurityUtilities.SignFile( cert, timestampUri, manifestFilePath );
}
}