如何使用Sha256 Cert for .NET 4.0签署ClickOnce,如Visual Studio Update 3

Oto*_*heA 10 command-line batch-file mage visual-studio-2013

我正在尝试使用clickonce安装程序部署Outlook加载项.我有一个几乎可以工作的批处理文件,但是,当我尝试在Windows XP上安装时,我收到错误"xml signature无效".众所周知,XP以SHA256证书为例失败.众所周知,Visual Studio 2013的Update 3修复了使用Visual Studio界面发布时的问题.我想知道如何在命令行上使用signtool或mage完成相同的修复.这是我当前的批处理文件,适用于除Windows XP之外的所有内容:

:: Build and publish
msbuild /target:clean,publish /property:MapFileExtensions=false /property:Configuration="Release" /property:ApplicationVersion="1.0.0.0" /property:InstallUrl="https://example.com" /property:UpdateEnabled="true" /property:UpdateMode="Foreground" /property:UpdateInterval="0" /property:UpdateIntervalUnits="days" /property:PublisherName="Example" /property:ProductName="Example Outlook Add-In" /property:FriendlyName="Example Outlook Add-In" /property:LoadBehavior="3" /property:BootstrapperEnabled="true" /property:IsWebBootstrapper="true"

:: Sign the exe
signtool sign /fd SHA1 /f "certificate.pfx" "publish\setup.exe"

:: Sign the application manifest
mage -sign "publish\Application Files\Example_1_0_0_0\Example.dll.manifest" -CertFile "certificate.pfx"
mage -update "publish\Application Files\Example_1_0_0_0\Example.dll.manifest" -CertFile "certificate.pfx" -algorithm sha1RSA

:: Sign the deployment manifests (there are 2 locations)
mage -update "publish\Application Files\Example_1_0_0_0\Example.vsto" -appmanifest "publish\Application Files\Example_1_0_0_0\Example.dll.manifest" -CertFile "certificate.pfx" -algorithm sha1RSA
mage -update "publish\Example.vsto" -appmanifest "publish\Application Files\Example_1_0_0_0\Example.dll.manifest" -CertFile "certificate.pfx" -algorithm sha1RSA
Run Code Online (Sandbox Code Playgroud)

我已经尝试了很多这个脚本的调整,这是我得到的地方.如果我使用Visual Studio"立即发布"按钮使用相同的certificate.pfx发布,一切正常,但我想让它在命令行上进行自动化.

小智 8

正如user2404450正确编写的那样,任何VS 2013更新中包含的Mage都无法解决问题.Microsoft已更新API,但未更新mage.exe工具.如果在调用mage.exe时添加"-algorithm sha1RSA"参数,则只需指定在为应用程序资源生成哈希时使用的摘要算法.

为了解决这个问题,我们编写了一个调用正确API的小工具,请参阅示例:

Microsoft.Build.Tasks.Deployment.ManifestUtilities.SecurityUtilities.SignFile(certThumbprint, timestampUrl, path, "v4.0");
Run Code Online (Sandbox Code Playgroud)

您必须安装VS 2013 Update 3才能使第4个参数正常工作.