title: ClickOnce VSTO solution signed with mage.exe - certificate not trusted error
body: <p>I'm trying to deploy a VSTO solution, which are 2 addins for Word and for Outlook, using ClickOnce. Due to our deployment infrastructure/practices, I cannot publish it using Visual Studio, it is instead built on a build server and deployed via a deployment server.</p>
  
  <p>For local development, a self-signed certificate is used. The deployment worked with this self-signed certificate (if the the self-signed certificate was installed on the machine), but now I want to add a real company certificate so that the application can be deployed to the users.</p>
  
  <p>During deployment, after the configuration files are poked, they are updated and re-signed with the real certificate. However, this produces the following error during installation:</p>
  
  <pre><code>System.Security.SecurityException: Customized functionality in this application will not work because the certificate used to sign the deployment manifest for &lt;app name&gt; or its location is not trusted. Contact your administrator for further assistance.
         at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInTrustEvaluator.VerifyTrustPromptKeyInternal(ClickOnceTrustPromptKeyValue promptKeyValue, DeploymentSignatureInformation signatureInformation, String productName, TrustStatus status)
         at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInTrustEvaluator.VerifyTrustUsingPromptKey(Uri manifest, DeploymentSignatureInformation signatureInformation, String productName, TrustStatus status)
         at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInTrustEvaluator.VerifyTrustUsingPromptKey(Uri manifest, DeploymentSignatureInformation signatureInformation, String productName)
         at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.ProcessSHA1Manifest(ActivationContext context, DeploymentSignatureInformation signatureInformation, PermissionSet permissionsRequested, Uri manifest, ManifestSignatureInformationCollection signatures, AddInInstallationStatus installState)
         at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.VerifySecurity(ActivationContext context, Uri manifest, AddInInstallationStatus installState)
         at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()
      The Zone of the assembly that failed was:
      MyComputer
  </code></pre>
  
  <p>The only lead I have is that, after re-signing, the values in publisherIdentity element are not changed (both .vsto and .manifest), only the Signature element has values corresponding to the new certificate.</p>
  
  <p>Following commands are used to sign the .vsto and .manifest files (as far as I can see from the deployment scripts):</p>
  
  <pre><code>mage.exe -Update "[path to .vsto/.manifest]"
  mage.exe -Sign "[path to .vsto/.manifest]" -CertHash [certificateHash]
  </code></pre>
  
  <p>where [certificateHash] is the thumbprint of the real certificate and is used to look up the certificate in certificates stores. I'm told this is security measure so that the certificate file doesn't have to be distributed along with the deployment package.</p>
  
  <p>After signing, the files have their Signature values changed, but the publisherIdentity still has the name and issuerKeyHash of the self-signed certificate.</p>
  
  <p>I tried poking these two values prior to re-signing, but I'm don't know how to calculate the issuerKeyHash.</p>
  
  <p>Any advise on how to proceed would be much appreciated!</p>
  
  <p>Edit:<br>
  I was trying out other mage.exe parameters, like '-TrustLevel FullTrust' (which didn't have any effect) or '-UseManifestForTrust True' along with Name and Publisher parameters, which yielded this error message (which is different than the one mentioned above).</p>
  
  <pre><code>************** Exception Text **************
  System.InvalidOperationException: You cannot specify a &lt;useManifestForTrust&gt; element for a ClickOnce application that specifies a custom host.
     at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.GetManifests(TimeSpan timeout)
     at Microsoft.VisualStudio.Tools.Applications.Deployment.ClickOnceAddInDeploymentManager.InstallAddIn()
  </code></pre>
  
  <p>.</p>