title: Modify a C# Manifest using the sha256 algorithm for the DigestMethod
body: <p>I need to update a .NET 4.5.1 application manifest, ensuring that the DigestMethod stays as a sha256 hash.</p>
  
  <p>Here's why: I initially deploy a WPF app with ClickOnce to a dev environment, and then a script configures, signs and copies the app to a particular production environment.  I have an existing script that does this, but after upgrading to .NET 4.5.1 from .NET 4.0 the script no longer works.  I think this is due to a change in the default manifest hashing algorithm from sha1 to sha256 in those .NET versions.</p>
  
  <p>The relevant part of the script is very small:</p>
  
  <pre><code>using Microsoft.Build.Tasks.Deployment.ManifestUtilities;
  // This comes from Microsoft.Build.Tasks.v12.0.dll
  
  public class Program
      {
          public static void Main(string[] args)
              {
                  // set up...
  
                  DeployManifest manifest= ManifestReader.ReadManifest(manifestPath, true) as DeployManifest;
  
                  // I perform some updates to the manifest...
  
                  ManifestWriter.WriteManifest(manifest);
              }
      }
  }
  </code></pre>
  
  <p>Even if I simply read the manifest and write it out again, without doing any updates, the DigestMethod Algorithm changes from sha256 to sha1 as shown in manifest files below:</p>
  
  <p>Original manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2"&gt;
    &lt;assemblyIdentity name="program.application" version="1.9.9.10" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="amd64" xmlns="urn:schemas-microsoft-com:asm.v1" /&gt;
    &lt;description asmv2:publisher="me" asmv2:product="program (dev)" xmlns="urn:schemas-microsoft-com:asm.v1" /&gt;
    &lt;deployment install="true" mapFileExtensions="true" /&gt;
    &lt;compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2"&gt;
      &lt;framework targetVersion="4.5.1" profile="Full" supportedRuntime="4.0.30319" /&gt;
    &lt;/compatibleFrameworks&gt;
    &lt;dependency&gt;
      &lt;dependentAssembly dependencyType="install" codebase="Application Files\program_1_9_9_10\program.exe.manifest" size="44259"&gt;
        &lt;assemblyIdentity name="program.exe" version="1.9.9.10" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="amd64" type="win32" /&gt;
        &lt;hash&gt;
          &lt;dsig:Transforms&gt;
            &lt;dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /&gt;
          &lt;/dsig:Transforms&gt;
          &lt;dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" /&gt;
          &lt;dsig:DigestValue&gt;0R79PRqWqhrE60GSHC/rE2WczQ4jqxCKBGr4lsjS4ZE=&lt;/dsig:DigestValue&gt;
        &lt;/hash&gt;
      &lt;/dependentAssembly&gt;
    &lt;/dependency&gt;
  &lt;/asmv1:assembly&gt;
  </code></pre>
  
  <p>Rewritten manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2"&gt;
    &lt;assemblyIdentity name="program.application" version="1.9.9.10" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="amd64" xmlns="urn:schemas-microsoft-com:asm.v1" /&gt;
    &lt;description asmv2:publisher="me" asmv2:product="program (dev)" xmlns="urn:schemas-microsoft-com:asm.v1" /&gt;
    &lt;deployment install="true" mapFileExtensions="true" /&gt;
    &lt;dependency&gt;
      &lt;dependentAssembly dependencyType="install" codebase="Application Files\program_1_9_9_10\program.exe.manifest" size="44259"&gt;
        &lt;assemblyIdentity name="program.exe" version="1.9.9.10" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="amd64" type="win32" /&gt;
        &lt;hash&gt;
          &lt;dsig:Transforms&gt;
            &lt;dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /&gt;
          &lt;/dsig:Transforms&gt;
          &lt;dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /&gt;
          &lt;dsig:DigestValue&gt;0R79PRqWqhrE60GSHC/rE2WczQ4jqxCKBGr4lsjS4ZE=&lt;/dsig:DigestValue&gt;
        &lt;/hash&gt;
      &lt;/dependentAssembly&gt;
    &lt;/dependency&gt;
    &lt;compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2"&gt;
      &lt;framework targetVersion="4.5.1" profile="Full" supportedRuntime="4.0.30319" /&gt;
    &lt;/compatibleFrameworks&gt;
  &lt;/asmv1:assembly&gt;
  </code></pre>
  
  <p>Notice the difference between the two is the change from sha256 to sha1 in the dsig:DigestMethod element.  Strangely, the DigestValue has not changed.  This ultimately leads to an error when I try to run the deployed application, along the lines of ""xxxx has a different computed hash than specified in manifest."</p>
  
  <p>I have shown the Deploy Manifest here, but I see the same effect happening with the Application Manifest.</p>
  
  <p>I think if I can write the manifest out with a sha256 hash, it will solve my problem.  Does anyone know how to do this?  Any suggestions would be much appreciated.</p>