在MSI安装vb.net期间配置App.config应用程序设置

在MSI安装vb.net期间配置App.config应用程序设置,vb.net,windows-services,windows-installer,app-config,Vb.net,Windows Services,Windows Installer,App Config,我正在尝试为我的windows服务创建msi安装。创建msi的原因是,预期用户希望能够在尽可能少的干预下快速安装服务 我可以让服务作为msi安装,但我的代码中有一个变量,需要用户在安装msi时定义该变量。我要求用户提供的变量是他们希望我的服务创建的xml文件所在的文件路径 我想我可以将app.config应用程序设置配置为包含xml文件应该写入的文件路径。然而,我正在努力做到这一点,我不确定这是否是最好的方法 我有一个包含可执行文件的安装项目,还有一个包含用户变量的文本框。 我有一个insta

我正在尝试为我的windows服务创建msi安装。创建msi的原因是,预期用户希望能够在尽可能少的干预下快速安装服务

我可以让服务作为msi安装,但我的代码中有一个变量,需要用户在安装msi时定义该变量。我要求用户提供的变量是他们希望我的服务创建的xml文件所在的文件路径

我想我可以将app.config应用程序设置配置为包含xml文件应该写入的文件路径。然而,我正在努力做到这一点,我不确定这是否是最好的方法

我有一个包含可执行文件的安装项目,还有一个包含用户变量的文本框。

我有一个installer类,其中包含我的serviceinstaller和process installer。这就是我努力理解下一步需要做什么的地方。 我需要重写安装方法吗?我的installer类的当前代码是自动生成的,如下所示:

Imports System.Configuration.Install
Imports System.Configuration

<System.ComponentModel.RunInstaller(True)> Partial Class ProjectInstaller
Inherits System.Configuration.Install.Installer

'Installer overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    Try
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
    Finally
        MyBase.Dispose(disposing)
    End Try
End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.  
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
    Me.ServiceProcessInstaller1 = New System.ServiceProcess.ServiceProcessInstaller()
    Me.ServiceInstaller1 = New System.ServiceProcess.ServiceInstaller()
    '
    'ServiceProcessInstaller1
    '
    Me.ServiceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem
    Me.ServiceProcessInstaller1.Password = Nothing
    Me.ServiceProcessInstaller1.Username = Nothing
    '
    'ServiceInstaller1
    '
    Me.ServiceInstaller1.ServiceName = "Spotter"
    Me.ServiceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic
    '
    'ProjectInstaller
    '
    Me.Installers.AddRange(New System.Configuration.Install.Installer() {Me.ServiceProcessInstaller1, Me.ServiceInstaller1})

End Sub

Friend WithEvents ServiceProcessInstaller1 As System.ServiceProcess.ServiceProcessInstaller
Friend WithEvents ServiceInstaller1 As System.ServiceProcess.ServiceInstaller

End Class
导入System.Configuration.Install
导入系统配置
部分类投影装入器
继承System.Configuration.Install.Installer
'安装程序重写dispose以清理组件列表。
_
受保护的重写子处置(ByVal作为布尔值处置)
尝试
如果处理AndAlso组件不是什么,那么
components.Dispose()
如果结束
最后
MyBase.Dispose(Dispose)
结束尝试
端接头
'是组件设计器所必需的
作为System.ComponentModel.IContainer的专用组件
'注意:组件设计器需要以下步骤
'可以使用组件设计器对其进行修改。
'不要使用代码编辑器修改它。
_
私有子初始化组件()
Me.ServiceProcessInstaller1=新系统.ServiceProcess.ServiceProcessInstaller()
Me.ServiceInstaller1=新系统.ServiceProcess.ServiceInstaller()
'
'ServiceProcessInstaller1
'
Me.ServiceProcessInstaller1.Account=System.ServiceProcess.ServiceAccount.LocalSystem
Me.ServiceProcessInstaller1.Password=无
Me.serviceprocesinstaller1.Username=无
'
'服务安装程序1
'
Me.ServiceInstaller1.ServiceName=“Spotter”
Me.ServiceInstaller1.StartType=System.ServiceProcess.ServiceStartMode.Automatic
'
'投射器
'
Me.Installers.AddRange(新的System.Configuration.Install.Installer(){Me.ServiceProcessInstaller1,Me.ServiceInstaller1})
端接头
Friend WithEvents ServiceProcessInstaller1作为System.ServiceProcess.ServiceProcessInstaller
Friend WithEvents ServiceInstaller1作为System.ServiceProcess.ServiceInstaller
末级
我甚至可以添加CustomActionData值。该字符串确定传递到上下文对象的内容,我使用该对象收集输入的用户值。param1是我的变量名。


我很难与安装程序代码……我想,

< P>一个选项是使用第三方安装程序,如安装掩护,它支持修改XML配置文件,如配置文件。 但是,如果您想自己启动,您肯定需要覆盖Install方法。在CustomData中传递的任何参数都将在作为参数传递到此方法的字典中可用

例如:

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

    If Me.Context.Parameters.Count <> 0 Then

        For Each sKey As String In Context.Parameters.Keys
            Select Case sKey.ToUpper
                Case "PARAM1"
                    ' XML directory
                    Me.XMLDir = Context.Parameters(sKey)

            End Select
        Next
    End If
End Sub
Public Overrides子安装(ByVal stateSaver作为System.Collections.IDictionary)
MyBase.Install(stateSaver)
如果Me.Context.Parameters.Count为0,则
将每个sKey作为Context.Parameters.Keys中的字符串
选择Case sKey.ToUpper
案件“1”
'XML目录
Me.XMLDir=Context.Parameters(sKey)
结束选择
下一个
如果结束
端接头
在这种情况下,我们总是将值写入注册表,以便用户在卸载或重新安装时不必重新输入

我不确定修改app.config的事件的确切顺序,但您可以写入注册表,然后在服务首次启动时修改app.config


您可能还会发现,为了使安装程序能够成功运行,您需要从提交阶段删除自定义操作。

感谢您的回复。通读你的例子,我很难完全理解。什么是变量Me.XMLDir?该变量只是显示提取在customdata中传递的值。这是您将用于更新app.config的内容。