Visual Studio 如何在MAUI中发布时对Application.exe进行数字签名?

eagi6jfj  于 2023-11-21  发布在  其他
关注(0)|答案(1)|浏览(208)

我们要发布的MAUI应用程序后,数字签名的应用程序主.DLL和.EXE文件使用DigiCert硬件令牌证书。
我们遵循的步骤是:
1.在发布模式下重新生成项目
1.通过DigiCert硬件令牌对Bin和Obj文件夹中存在的DLL和EXE的相应文件进行数字签名
1.以发布模式发布项目
1.在发布过程中,它可以选择添加证书,因此我们添加DigiCert相应的证书(以便在发布后签署msix文件)。
在步骤4之后,使用数字签名成功创建了软件包(MSIX文件),并准备安装。
安装后,应用程序文件存在于C:\Programs Files\WindowsApps文件夹中,在这里,在EXE文件中找不到数字签名,即从EXE文件中删除数字签名,但DLL文件中存在数字签名。
我们还尝试了POST BUILD事件,在发布之前,数字签名存在于EXE和DLL中,但在发布之后,数字签名从EXE中删除。
我们希望在dll和exe上都保留数字签名。请提供您的建议。

avkwfej4

avkwfej41#

解决方案是使用makeappx.exe解压缩msix包,使用signtool.exe对application.exe和application.dll进行签名,然后再次将其打包到msix包中,并再次对msix包进行签名。
下面是一个基本的PowerShell脚本。

  1. try {
  2. $CurrentDirectory = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path)
  3. Set-Location -Path $CurrentDirectory
  4. # Set Environment Variable to your Windows Kit so signtool and makeappx.exe could be found
  5. $env:PATH += ";C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\"
  6. # script assume it will run from same directory as msix package and there will be only 1 msix.
  7. $MsixFile = Get-ChildItem $buildFolderPath -Filter "*.msix" | Select-Object -First 1
  8. # Important: FolderName should match with MSIX file Name
  9. $MsixFolderName = [System.IO.Path]::GetFileNameWithoutExtension($MsixFile.Name)
  10. $UnpackFolderPath = Join-Path -Path $CurrentDirectory -ChildPath ("UnpackFolder\$MsixFolderName")
  11. $DllFilePath = Join-Path -Path $UnpackFolderPath "MyMauiApp.dll"
  12. $AppFilePath = Join-Path -Path $UnpackFolderPath "MyMauiApp.exe"
  13. mkdir $UnpackFolderPath
  14. # Unpack the MSIX to a temp folder created.
  15. makeappx.exe unpack /d $UnpackFolderPath /p $MsixFile.FullName
  16. # Backup orginal MSIX
  17. $BackupMsixPath = $MsixFile.FullName + ".bak"
  18. Rename-Item -Path $MsixFile.FullName -NewName $BackupMsixPath
  19. # Sign MyMauiApp.dll
  20. signtool.exe sign /fd SHA256 /a /t http://timestamp.digicert.com /n "Certificate Common Name" $DllFilePath
  21. #Sign MyMauiApp.exe
  22. signtool.exe sign /fd SHA256 /a /t http://timestamp.digicert.com /n "Certificate Common Name" $AppFilePath
  23. #Pack MSIX package.
  24. makeappx.exe pack /d $UnpackFolderPath /p $MsixFile.FullName
  25. #Sign MSIX package.
  26. signtool.exe sign /fd SHA256 /a /t http://timestamp.digicert.com /n "Certificate Common Name" $MsixFile.FullName
  27. }
  28. catch {
  29. Write-Error "Failed to sign"
  30. }

字符串

展开查看全部

相关问题