文件具有与清单中指定的不同的计算哈希

文件具有与清单中指定的不同的计算哈希

本文介绍了“文件具有与清单中指定的不同的计算哈希".签署EXE时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ClickOnce安装失败,并显示以下错误:

My ClickOnce installation fails with an error:

我使用MSBuild生成ClickOnce部署程序包.构建脚本中的相关行:

I use MSBuild to generate ClickOnce deployment package. The relevant line from the build script:

<MSBuild Targets="Publish"
         Projects="WindowsFormsProject.csproj"
         ContinueOnError="false" />

WindowsFormsProject.csproj具有对可执行文件进行签名的Post-Build步骤,如下所示:

The WindowsFormsProject.csproj has a Post-Build step that signs the executable, as follows:

signtool sign /a $(ProjectDir)\obj\$(PlatformName)\$(ConfigurationName)\$(TargetFileName)

问题是,当我查看构建日志时,我发现清单是在执行Post-Build事件之前生成的.因此,哈希码不匹配也就不足为奇了.构建日志中的相关行:

The trouble is, when I look at the build log I see that the manifest is generated BEFORE the Post-Build event executes. So it's not surprising that hash codes don't match. The relevant lines from the build log:

WindowsFormsProject-> ... \ WindowsFormsProject.application

WindowsFormsProject -> ...\WindowsFormsProject.application

...

PostBuildEvent:

PostBuildEvent:

成功签名:... \ WindowsFormsProject.exe

Successfully signed: ...\WindowsFormsProject.exe

所以,问题是:

  1. 在< MSBuild>期间生成清单之前,有没有一种方法可以对程序集进行签名.任务?
  2. 在构建完成之后,是否有一种方法可以重新生成清单(且仅清单),以便哈希码再次匹配?

或者,如果您能想到其他解决方案,我将不胜感激.

Or, if you can think of a different solution to the problem, I'd appreciate your ideas.

推荐答案

如果您使用的是MSBuild 4,则可以在创建程序集之后并且在执行任何其他步骤之前,使用 AfterTargets 属性对程序集进行签名.被采取.删除您的构建后步骤,然后将此块添加到您的项目中:

If you are using MSBuild 4, you can use AfterTargets property to sign assembly just after it was created and before any further steps will be taken. Remove your post-build step and add this block to your project instead:

<Target Name="SignOutput" AfterTargets ="CoreCompile">
  <PropertyGroup>
    <TimestampServerUrl>http://timestamp.verisign.com/scripts/timstamp.dll</TimestampServerUrl>
  <ApplicationDescription>Foo bar</ApplicationDescription>
  <SigningCertificateCriteria>/sha1 578a9486f10ed1118f2b5f428afb842e3f374793</SigningCertificateCriteria>
  </PropertyGroup>
  <ItemGroup>
    <SignableFiles Include="$(ProjectDir)obj\$(PlatformName)\$(ConfigurationName)\$(TargetName)$(TargetExt)" />
  </ItemGroup>
  <GetFrameworkSdkPath>
          <Output
              TaskParameter="Path"
              PropertyName="SdkPath" />
  </GetFrameworkSdkPath>
    <Exec Command="&quot;$(SdkPath)bin\signtool&quot; sign $(SigningCertificateCriteria) /d &quot;$(ApplicationDescription)&quot; /t &quot;$(TimestampServerUrl)&quot; &quot;%(SignableFiles.Identity)&quot;" />
</Target>

这篇关于“文件具有与清单中指定的不同的计算哈希".签署EXE时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 23:47