Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义操作赢得';不能在WIX安装程序中运行_Wix_Custom Action - Fatal编程技术网

自定义操作赢得';不能在WIX安装程序中运行

自定义操作赢得';不能在WIX安装程序中运行,wix,custom-action,Wix,Custom Action,我正在尝试创建一个MSI,其唯一目的是在Windows 7计算机上安装“Microsoft根证书颁发机构2011”证书,然后将.NET Framework安装程序作为WIX boostrapper的一部分运行。由于在.NET 4.8安装之前,我还没有找到从引导程序安装此证书的其他方法,因此我决定创建一个MSI,其中包含安装证书的自定义操作,然后将其添加到MSI包调用的链中。我现在正在单独测试安装程序。因此,基本上我已经构建了自定义操作,并将其添加到WIX设置项目中。但是,在构建之后,当我运行ms

我正在尝试创建一个MSI,其唯一目的是在Windows 7计算机上安装“Microsoft根证书颁发机构2011”证书,然后将.NET Framework安装程序作为WIX boostrapper的一部分运行。由于在.NET 4.8安装之前,我还没有找到从引导程序安装此证书的其他方法,因此我决定创建一个MSI,其中包含安装证书的自定义操作,然后将其添加到MSI包调用的链中。我现在正在单独测试安装程序。因此,基本上我已经构建了自定义操作,并将其添加到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 setup 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包执行此操作,只需使用WiX IIS扩展将证书安装到适当的证书存储中即可


如果我打算使用自己的代码来实现这一点,我只需将其作为一个无窗口控制台应用程序编写,并将其作为EXE包连接到引导程序。您也可以编写一个注册表值,以便在检测条件下使用,但如果您不介意的话,反复运行该程序可能不会有害。

如果您想在引导程序包中作为MSI包来执行此操作,只需使用WiX IIS扩展将证书安装到适当的证书存储中即可

如果我打算使用自己的代码来实现这一点,我只需将其作为一个无窗口控制台应用程序编写,并将其作为EXE包连接到引导程序。您也可以编写一个注册表值,以便在检测条件下使用,但如果您不介意的话,反复运行该程序可能不会有什么害处。

现在没有时间查看。(你可能已经有了)。现在没时间看了。(你可能已经有了)。