[英]Custom Action Won't Run in WIX Installer
我正在嘗試創建一個 MSI,其唯一目的是在 Windows 7 機器上安裝“Microsoft Root Certificate Authority 2011”證書,然后將 .NET 框架安裝程序作為 ZC4864F72BEA486B18E3FFRAPED477 booster46 的一部分運行。 由於在安裝 .NET 4.8 之前我還沒有找到從引導程序安裝此證書的另一種方法,因此我決定創建一個 MSI,其中包含安裝證書的自定義操作,然后將其添加到 MSIPackage 調用的鏈中。 我現在正在單獨測試安裝程序。 所以,基本上我已經構建了自定義操作,並將其添加到 WIX 設置項目中。 但是,在構建之后,當我運行 msi 時,沒有安裝證書。 作為自定義操作的一部分,我添加了一個要創建的文件,只是為了查看它是否正在運行,但也從未創建過該文件。
我的自定義操作如下:
[CustomAction]
public static ActionResult CheckForExistingCertificate(Session session)
{
session.Log("Starting CheckForExistingCertificate");
var logFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
@"\CertificateInstallInfo";
if (!File.Exists(logFile))
File.Create(logFile);
try
{
session.Log("***** Beginning LocalMachine Certificate Store Search...");
X509Store lmStore = new X509Store(StoreName.CertificateAuthority,
StoreLocation.LocalMachine);
lmStore.Open(OpenFlags.ReadOnly);
session.Log("***** lmStore.Certificates.Count = " + lmStore.Certificates.Count);
foreach (X509Certificate2 cert in lmStore.Certificates)
{
session.Log("lmCertificate Listing : " + cert.FriendlyName);
if (cert.FriendlyName == "Microsoft Root Certificate Authority 2011")
{
session["INTERMEDIATECERTIFICATEALREADYINSTALLED"] = "TRUE";
}
}
session.Log("***** Beginning CurrentUser Certificate Store Search...");
X509Store cuStore = new X509Store(StoreName.CertificateAuthority, StoreLocation.CurrentUser);
cuStore.Open(OpenFlags.ReadOnly);
session.Log("***** cuStore.Certificates.Count = " + cuStore.Certificates.Count);
foreach (X509Certificate2 cert in cuStore.Certificates)
{
session.Log("cuCertificate Listing : " + cert.FriendlyName);
if (cert.FriendlyName == "Microsoft Root Certificate Authority 2011")
{
session["INTERMEDIATECERTIFICATEALREADYINSTALLED"] = "TRUE";
}
}
if (session["INTERMEDIATECERTIFICATEALREADYINSTALLED"] == "FALSE")
{
X509Certificate2 certificate = new X509Certificate2("MicrosoftRootCertificateAuthority2011.cer");
X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.Add(certificate);
store.Close();
}
}
catch (Exception ex)
{
File.WriteAllText(logFile, ex.ToString());
session.Log("CheckForExistingCertificate - in catch");
}
session.Log("Ending CheckForExistingCertificate - end of function");
return ActionResult.Success;
}
我的 WIX 設置 Product.wxs 文件是:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Install Certificates" Language="1033" Version="1.0.0.0" Manufacturer="Just Joe Applications" UpgradeCode="68d00e98-21a2-480f-bb3a-be3049995f3c">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<!--<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />-->
<MediaTemplate />
<Binary Id="CustomActionBinary" SourceFile="$(var.InstallCertificateAction.TargetDir)$(var.InstallCertificateAction.TargetName).CA.dll" />
<CustomAction Id="InstallCert" Impersonate="no" BinaryKey="CustomActionBinary" DllEntry="CheckForExistingCertificate" Execute="deferred" Return="check" />
<InstallExecuteSequence>
<Custom Action="InstallCert" After="InstallInitialize"/>
</InstallExecuteSequence>
<Feature Id="ProductFeature" Title="Install Certificates" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Install Certificates" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
</ComponentGroup>
</Fragment>
</Wix>
如果您想在引導程序包中作為 MSI Package 執行此操作,只需使用 WiX IIS 擴展將證書安裝到正確的證書存儲中。
如果我要使用自己的代碼來執行此操作,我只需將其編寫為無窗口控制台應用程序,並將其作為 EXE Package 連接到引導程序。 您也可以編寫一個注冊表值以在檢測條件下使用,但如果您不打擾,一遍又一遍地運行程序可能無害。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.