【问题标题】:Convert a VS Setup Project Custom Action to InstallShield Project Custom Action将 VS 设置项目自定义操作转换为 InstallShield 项目自定义操作
【发布时间】:2011-10-20 21:45:28
【问题描述】:

我有一个标准的 Visual Studio 设置项目,我正在将其转换为 InstallShield LE 项目。

我在 CustomActions-Install-PrimaryOutputFromMyProject(Active) - CustomActionData - /sectionName="userSettings/SSE.My.MySettings" /provName="DPAPIProtection"

下有以下自定义操作

如何在 InstallShield 中重新创建此自定义操作?

这是我的安装程序类中的代码,它所做的只是保护 app.config 文件的某些部分:

Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.Configuration

'// This file encrypts the app.config file
Public Class CustomInstaller
    Inherits Installer
    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()

        'Add initialization code after the call to InitializeComponent

    End Sub
    Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
        MyBase.Install(stateSaver)

        'get Configuration section 
        'name from custom action parameter
        Dim sectionName As String = Me.Context.Parameters("sectionName")

        'get Protected Configuration Provider 
        'name from custom action parameter
        Dim provName As String = Me.Context.Parameters("provName")

        ' get the exe path from the default context parameters
        Dim exeFilePath As String = Me.Context.Parameters("assemblypath")

        'encrypt the configuration section
        ProtectSection(sectionName, provName, exeFilePath)
    End Sub
    Private Sub ProtectSection(ByVal sectionName As String, ByVal provName As String, ByVal exeFilePath As String)
        Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(exeFilePath)
        Dim section As ConfigurationSection = config.GetSection(sectionName)

        If Not section.SectionInformation.IsProtected Then
            'Protecting the specified section with the specified provider
            section.SectionInformation.ProtectSection(provName)
        End If
        section.SectionInformation.ForceSave = True
        config.Save(ConfigurationSaveMode.Modified)
    End Sub

End Class

【问题讨论】:

    标签: visual-studio installshield


    【解决方案1】:

    你应该阅读我的增强系列:

    Augmenting InstallShield using Windows Installer XML - Certificates

    Augmenting InstallShield using Windows Installer XML - Windows Services

    基本上我会这样做:

    1) 将 InstallerClass (InstallUtil) 自定义操作中的代码重构为 WiX DTF 自定义操作。这一步在技术上是可选的,但如果你知道与 InstallUtil 相关的所有可怕的事情,你就会这样做。

    2) 创作一个 WiX 合并模块以将 DLL 作为自定义操作使用并在 ModuleExecuteSequence 表中对其进行排序。

    3) 将合并模块添加到您的 InstallShield LE 项目中。

    注意:InstallShield 2010LE 基本上是精简的功能集软件。您可以使用它以 1500 美元的价格将其升级到 InstallShield 专业版。如果你能证明这一点,我会这样做。现实情况是 LE 有一些功能,我可以想出一些创造性的方法来增强它,但在普通 InstallShield 中更容易做到。

    【讨论】:

    • 感谢您的帮助,最初大部分内容都超出了我的想象。过去几天我一直在谷歌搜索,现在我对你的建议有了更好的理解。我已将我的代码添加到原始帖子中,您可以在查看后进一步说明情况吗?
    • 您可能希望查看您的 VDPROJ 使用 ORCA 生成的 MSI,并了解实现您的 CA 的基础表数据。从那里您必须弄清楚如何在 InstallShield 中进行操作。
    • 这一切都变得非常复杂,至少对我来说是这样。我要做的就是保护 app.config 文件。似乎找到另一种保护它的方法或返回使用 Windows 设置项目而不是 installshield 可能更容易。非常令人沮丧。
    • 好吧,我大概可以在大约一个小时内教你怎么做。在使用 CustomActionData 模式对字典进行序列化和反序列化时,涉及的内容很多。回答一个问题很难解释清楚。
    • 谢谢克里斯托弗,我完全明白了。我的沮丧当然不是针对你,我只是感到失望,因为在 VS 安装项目中保护 app.config 是一个简单的过程,但在 installshield 中要困难得多,我真的很喜欢使用 installshield。
    【解决方案2】:

    InstallShield 并不真正支持项目输出自定义操作。这是因为 Windows Installer 使用 EXE 和 DLL 自定义操作作为特定文件,而不是作为动态输出。

    此外,InstallShield LE 不支持 DLL 自定义操作。因此您只能使用 EXE、VBScript 或 JScript。

    由于您使用了 CustomActionData,我猜您的项目输出是一个 DLL。您不能在 InstallShield LE 中创建 DLL 自定义操作。

    【讨论】:

    • 感谢您的回复。我不确定你的意思,因为我确实添加了一个项目输出。
    • 我使用的是解决方案资源管理器。忘记了项目助手支持的项目输出。我更新了我的答案。
    • 即使 InstallShield 不支持项目引用,修改 .isproj 文件以注入 msbuild 复制任务以将文件带到相对路径位置也是微不足道的。
    猜你喜欢
    • 1970-01-01
    • 2010-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多