【问题标题】:Windows Installer runs custom action code not in the right sequence and failsWindows Installer 以不正确的顺序运行自定义操作代码并失败
【发布时间】:2015-07-23 10:45:24
【问题描述】:

我有一个非常奇怪的情况,自定义操作代码没有同步运行。
正如您在日志中可以看到的那样,“WinRoot dir”日志行应该出现在“CommonFiles Dir”行之后。然而它出现在最后。

这是代码:

[CustomAction]
    public static ActionResult CCCA_LogProductName(Session session)
    {
        productName = session[InstallShieldConstants.productName];
        CustomActionData customActionData = new CustomActionData();

        // log properties
        CCULog.LogMessageToFile(session, "CCCA_LogProductName", "INSTALLDIR : " +
                                session[InstallShieldConstants.installDir]);
        CCULog.LogMessageToFile(session, "CCCA_LogProductName", "Product Version : " +
                               session[InstallShieldConstants.productVersion]);
        CCULog.LogMessageToFile(session, "CCCA_LogProductName", "Source Dir : " +
                               session[InstallShieldConstants.sourceDir]);
        CCULog.LogMessageToFile(session, "CCCA_LogProductName", "Support Dir : " +
                               session[InstallShieldConstants.supportDir]);
        CCULog.LogMessageToFile(session, "CCCA_LogProductName", "CommonFiles Dir : " +
                               Environment.GetEnvironmentVariable("CommonProgramFiles"));
        CCULog.LogMessageToFile(session, "CCCA_LogProductName", "WinRoot Dir : " +
                               session[InstallShieldConstants.windowsVolumeDir]);

        customActionData.Add(InstallShieldConstants.productName, productName);
        session["CCCA_LogProductNameOnFirstTimeInstallStart"] = customActionData.ToString();
        session["CCCA_LogProductNameOnUninstallStart"] = customActionData.ToString();
        session["CCCA_LogProductNameOnUninstallEnd"] = customActionData.ToString();
        session["CCCA_LogProductNameOnInstallStart"] = customActionData.ToString();
        session["CCCA_LogProductNameOnInstallEnd"] = customActionData.ToString();

        return ActionResult.Success;
    }

虽然日志显示以下内容:

调用自定义操作 CosmoPublisherCustomActions!CosmoPublisherCustomActions.CCUCustomActions.CCCA_LogProductName 2015 年 7 月 23 日 11:24:44 :: CosmoPublisher:: CCCA_LogProductName :: 安装目录:C:\Program Files (x86)\CosmoCom\Server Components\ 2015 年 7 月 23 日 11:24:44 :: CosmoPublisher:: CCCA_LogProductName :: 产品 版本 : 7.2.0.119 07/23/2015 11:24:44 :: CosmoPublisher:: CCCA_LogProductName :: 源目录 : C:\Program Files (x86)\CosmoCom\Server Components\CosmoPublisherHotfixes\HF72-40106\ 2015 年 7 月 23 日 11:24:44 :: CosmoPublisher:: CCCA_LogProductName :: 支持 目录: C:\Users\SVCCOS~1\AppData\Local\Temp{D3407C75-8846-4DB4-8736-149A884053EF} 2015 年 7 月 23 日 11:24:44 :: CosmoPublisher:: CCCA_LogProductName :: CommonFiles 目录:C:\Program Files (x86)\Common Files MSI (s) (C4!70) [11:24:44:641]:属性更改:添加 CCCA_LogProductNameOnFirstTimeInstallStart 属性。它的值为 'ProductName=媒体服务.NET'。 MSI (s) (C4!70) [11:24:44:642]: 属性更改:添加 CCCA_LogProductNameOnUninstallStart 属性。 其值为“ProductName=Media Services .NET”。微星 (s) (C4!70) [11:24:44:642]:属性更改:添加 CCCA_LogProductNameOnUninstallEnd 属性。它的值为 'ProductName=媒体服务.NET'。 MSI (s) (C4!70) [11:24:44:642]: 属性更改:添加 CCCA_LogProductNameOnInstallStart 属性。 其值为“ProductName=Media Services .NET”。微星 (s) (C4!70) [11:24:44:642]:属性更改:添加 CCCA_LogProductNameOnInstallEnd 属性。它的值为 'ProductName=媒体服务.NET'。 2015 年 7 月 23 日 11:24:44 :: CosmoPublisher:: CCCA_LogProductName :: WinRoot 目录 : C:\ CustomAction CCCA_LogProductName 返回实际错误代码 1603(注意这可能不是 如果翻译发生在沙箱内,则为 100% 准确)操作已结束 11:24:44:CCCA_LogProductName。返回值 3. 动作于 11:24:44 结束: 安装。返回值 3。

我的 Installshield 自定义操作设置为“同步”,所以我不明白为什么会这样。奇怪的是,仅记录到文件的自定义操作失败了。
谢谢

编辑:
我的日志函数写入会话日志和本地文件:

/// <summary>
    /// Writing message to log file
    /// </summary>
    /// <param name="tag">tag of the log message.</param>
    /// <param name="message">message to write to log.</param>
    public static void LogMessageToFile(Session session, string tag, string message)
    {
        StreamWriter sw = File.AppendText(
            GetTempPath() + logFileName);
        try
        {
            string logLine = string.Format(
                "{0:G} :: {1} :: {2}", DateTime.Now, tag, message);
            sw.WriteLine(logLine);
            session.Log("{0:G} :: {1}:: {2} :: {3}", DateTime.Now, logTag, tag, message);
        }
        finally
        {
            sw.Close();
        }
    }  

【问题讨论】:

    标签: installshield windows-server-2012 custom-action windows-installer


    【解决方案1】:

    我很好奇为什么我们没有看到来自 DTF 的堆栈跟踪。 DTF 允许您附加调试器,我确信命令以正确的顺序运行。我从未见过 MSI 日志出现故障,但这是可能的。你可以试试 /l*v! (强调 ! )看看这是否会影响它出现的顺序。

    最简单的 CA 可能会失败。这就是为什么成为它们的主人或根本不做它们很重要的原因。

    【讨论】:

    • 您好,感谢您的回复。 “成为他们的主人”是什么意思?另外,您是否知道为什么只记录并返回 ActionResult.success 的简单 CA 会失败?谢谢!
    • 您没有向 CCULog.LogMessageToFile 显示源代码,因此无法说明它失败的原因。大师的传统定义是 10,000 小时的经验。这可能无法完全掌握“掌握”,但我的观点是声明式编程模型,自定义操作是迄今为止最常见的失败点。
    • 我已经用 Log 函数源代码更新了它。另外我仍然不明白为什么自定义操作是迄今为止最常见的失败点?它只是一个简单的自定义操作,写入日志并返回成功。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    • 2010-09-11
    • 1970-01-01
    • 2012-08-26
    • 2017-03-03
    • 2017-03-18
    • 1970-01-01
    相关资源
    最近更新 更多