将VS安装项目自定义操作转换为InstallShield项目自定义操作

时间:2011-10-20 21:45:29

标签: visual-studio installshield

我有一个标准的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

2 个答案:

答案 0 :(得分:3)

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

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中更容易做到。

答案 1 :(得分:1)

InstallShield实际上不支持项目输出自定义操作。这是因为Windows Installer将EXE和DLL自定义操作用作特定文件,而不是动态输出。

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

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