如何使用安装程序类在安装程序安装项目中的VB.net选项中正确添加?

时间:2018-10-09 19:25:17

标签: vb.net visual-studio

我有一个疑问,如何在安装过程中使用安装程序类从安装程序安装项目中选择选项?

这是添加到非项目设置中的安装程序类

Imports System.ComponentModel
Imports System.Configuration.Install

Public Class Installer1

    Public Sub New()
        MyBase.New()

        'El Diseñador de componentes requiere esta llamada.
        InitializeComponent()

        'Agregue el código de inicialización después de llamar a InitializeComponent
    End Sub

    Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
        MyBase.Install(stateSaver)
        Dim valor As String = Me.Context.Parameters.Item("BUTTON4")
        MsgBox(valor)
    End Sub 

End Class

在定义设置项目的自定义动作之后,在动作的“属性”字段中,CustomActionData = BUTTON4

enter image description here

接下来,向项目添加了四个按钮选项

enter image description here

但是,在运行安装程序MsgBox(valor)时,无论选择了哪个选项,都会显示一个空字符串,我是否丢失了某些内容?

1 个答案:

答案 0 :(得分:0)

将安装程序的输入选择传递给安装程序类的步骤是:

1:制作项目。 2:添加新元素->选择安装程序类 3:创建安装项目 4:在设置项目中->视图->用户界面 5-在开始添加按钮选项中

在我的情况下,请注意变量BUTTON4的名称包含在安装程序中选择的选项的值。

Image1

4:在安装项目中->视图->自定义操作 5:在“自定义操作”的“安装”文件夹中->“添加自定义” 选择项目的程序集,然后在字段CustomActionData中添加要在安装程序类中处理的变量名称

Image2

6:在安装程序类中,为安装程序中的选定操作执行操作,以我为例,编写一个配置文件

Imports System.ComponentModel

导入System.Configuration.Install

公共类安装程序1

Public Sub New()
    MyBase.New()

    'El Diseñador de componentes requiere esta llamada.
    InitializeComponent()

    'Agregue el código de inicialización después de llamar a InitializeComponent

End Sub

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

    Dim sIdioma As String = Me.Context.Parameters.Item("IDIOMA")
    Actualizar_Config_File(sIdioma)

End Sub

Private Sub Actualizar_Config_File(ByVal sIdioma As String)
    Dim sArchivo As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & DIR_DOC & DIR_CFIG
    Dim iNumeroArchivo As Integer = FreeFile() ' Obtiene un número
    Dim i As Integer = 0

    FileOpen(iNumeroArchivo, sArchivo, OpenMode.Output)

    For i = 0 To 1
        PrintLine(iNumeroArchivo, sIdioma)
    Next i

    FileClose(iNumeroArchivo) ' Cierra el archivo.
End Sub

结束班级