【问题标题】:How to make MSBuild sign all files in a Clickonce application如何让 MSBuild 对 Clickonce 应用程序中的所有文件进行签名
【发布时间】:2017-08-09 00:50:42
【问题描述】:

我有一个由 Clickonce 安装的应用程序 (WPF),现在我需要对其进行签名,以便 Windows 可以将我的公司识别为受信任的颁发者。在我的 C.I. 中使用了以下命令行。工具(带有菱形的参数仅用于举例说明情况):

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /target:clean;build;publish /p:ApplicationVersion=<VERSION> /p:SignAssembly=true /p:GenerateManifests=true /p:SignManifests=true /p:AssemblyOriginatorKeyFile=<PFX_PATH> /p:ManifestCertificateThumbprint=<CERTIFICATE_ID> /property:Configuration=<CONFIGURATION>;PublishDir=<PUBLISH_DIR>;BootstrapperEnabled=true;PublishUrl=<PUBLISH_URL>;InstallUrl=<INSTALL_URL>;UpdateUrl=<UPDATE_URL> C:\hudson\slave\workspace\NIMBUS-NFE-NFEasy2\NFeasy2\NFeasy2.sln

问题是:只有 setup.exe 被签名,并且只有 SHA-256 算法。因此,当用户运行我的应用程序时,无法识别发行者。此外,在 Windows XP 上运行时,安装程​​序将永远不会运行,因为 SO 无法识别签名(似乎 WinXP 需要 SHA-1)。

如何设置我的项目或命令行以使用 SHA-1 和 SHA-256 算法对所有文件进行签名?另外,这是否会在每次运行应用程序时停止提示用户许可?如果没有,有办法吗?

谢谢!

【问题讨论】:

    标签: c# clickonce sha


    【解决方案1】:

    通过互联网阅读了很多解决方案后,我设法编写了一个批处理文件来进行完整签名。请注意,这仅适用于特定版本,我必须按以下顺序将它们放入我的路径中:

    C:\Program Files (x86)\Windows Kits\8.1\bin\x86;
    
    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin;
    

    脚本如下:

    rem renaming the setup.exe because it will be treated separately
    ren setup.exe setup._
    
    rem removing the .DEPLOY extension, getting back the original one
    for /r %%x in (*.deploy) do ren "%%x" *.
    
    rem signing all files with my certificate
    for /r %%x in (*.exe *.dll) do signtool.exe sign /fd sha1 /as /sha1 <MY_CERTIFICATE> "%%x"
    for /r %%x in (*.exe *.dll) do signtool.exe sign /fd sha256 /as /sha1 <MY_CERTIFICATE> "%%x"
    
    rem updating the manifest with the new signatures
    for /r %%x in (*.manifest) do mage.exe -update "%%x"
    
    rem signing the manifest file
    for /r %%x in (*.manifest) do mage.exe -sign "%%x" -ch <MY_CERTIFICATE>
    
    rem putting the .DEPLOY extension in all files renamed previously
    for /r %%x in (*.exe *.dll *.config *.cer *.ttf *.ico *.xml *.p7b) do ren "%%x" *.*.deploy
    
    rem getting back setup.exe
    ren setup._ setup.exe 
    
    rem signing setup.exe file
    signtool.exe sign /fd sha1 /as /sha1 <MY_CERTIFICATE> setup.exe
    signtool.exe sign /fd sha256 /as /sha1 <MY_CERTIFICATE> setup.exe
    
    rem updating MyApp.Application file
    for /r %%x in (*.manifest) do mage.exe -update MyApp.Application -appm "%%x"
    
    rem signing MyApp.Application file
    mage.exe -sign MyApp.Application -ch <MY_CERTIFICATE>
    
    rem updating the new signed file to the destiny folder
    for /r %%x in (*.application) do xcopy MyApp.Application "%%x" /y
    

    【讨论】:

    • 我真的不敢相信这会奏效。谢谢你。漂亮的作品。
    • 这对我不起作用,我正在尝试签署 vsto click once 应用程序,但我收到“部署中的引用与应用程序清单中定义的身份不匹配”。运行此脚本后。有解决此问题的建议吗?
    • 我收回 - 这确实有效。如果它是 VSTO,这就是最后 3 个命令的样子(抱歉,新行在 cmets 中不起作用): rem 为 /r %%x in (.manifest) do mage.exe 更新 MyPlugin.vsto 文件-update MyPlugin.vsto -appm "%%x" rem 签名 MyPlugin.vsto 文件 mage.exe -sign MyPlugin.vsto -ch rem 将新签名文件更新到 /r %%x in (.vsto) 做 xcopy MyPlugin.vsto "%%x" /y
    猜你喜欢
    • 2013-11-07
    • 2016-04-26
    • 2010-10-27
    • 1970-01-01
    • 1970-01-01
    • 2011-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多