Fix codesign on Windows with the latest SDK

This commit is contained in:
Wojtek Figat
2024-03-28 18:55:05 +01:00
parent 21d5e63b93
commit 5525e895cf

View File

@@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Flax.Build;
using Flax.Build.Platforms;
using Flax.Build.Projects.VisualStudio;
@@ -288,10 +287,25 @@ namespace Flax.Deploy
var sdks = WindowsPlatformBase.GetSDKs();
if (sdks.Count == 0)
throw new Exception("No Windows SDK found. Cannot sign file.");
var sdkKeys = sdks.Keys.ToList();
sdkKeys.Sort();
var sdk = sdks[sdkKeys.Last()];
var signtool = Path.Combine(sdk, "bin", "x64", "signtool.exe");
var signtool = string.Empty;
foreach (var e in sdks)
{
try
{
var sdk = e.Value;
signtool = Path.Combine(sdk, "bin", "x64", "signtool.exe");
if (File.Exists(signtool))
break;
var ver = WindowsPlatformBase.GetSDKVersion(e.Key);
signtool = Path.Combine(sdk, "bin", ver.ToString(4), "x64", "signtool.exe");
if (File.Exists(signtool))
break;
}
catch
{
// Ignore version formatting exception
}
}
var cmdLine = string.Format("sign /debug /f \"{0}\" /p \"{1}\" /tr http://timestamp.comodoca.com /td sha256 /fd sha256 \"{2}\"", certificatePath, certificatePass, file);
Utilities.Run(signtool, cmdLine, null, null, Utilities.RunOptions.Default | Utilities.RunOptions.ThrowExceptionOnError);
}