c# - 如何让 MSBuild 对 Clickonce 应用程序中的所有文件进行签名

标签 c# clickonce sha

我有一个由 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:\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

关于c# - 如何让 MSBuild 对 Clickonce 应用程序中的所有文件进行签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42202446/

相关文章:

c# - 具有参数的WPF Mvvm导航

c# - 无法将 ASP.NET Core 2.1 Angular 应用程序部署到 Azure

.net - VS2012 .NET 4.0 Clickonce VSTO CryptographicException : SignatureDescription could not be created for the signature algorithm supplied

wpf - WPF/Winforms/ClickOnce/的统计使用情况

clickonce - 是否可以预先生成NGen镜像,以便客户不必这样做?

ssl - SHA-2 在互联网安全中的作用是什么?

c# - volatile 在 C# 的单线程应用程序中有用吗?

c++ - 散列重定向的 DOS 输出

paypal - Barclaycard ePDQ - 自定义用户生成的金额

c# - 在 C# 中将字符串拆分为特定格式?