2012-02-01 131 views
0

我正在尝试为我的Windows服务创建msi安装。创建msi的原因是,预期的用户希望能够尽可能少地进行干预来快速安装服务。在MSI安装期间配置App.config应用程序设置vb.net

我可以得到安装为msi的服务,但我的代码中有一个变量,我需要用户定义msi的安装时间。我从用户需要的变量是他们希望我的服务创建的xml文件位于的文件路径。

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

我有我的安装项目,其中包含我的可执行文件,并有我的文本框将包含用户的一个变量。 setup project

我有一个安装程序类,其中包含我的serviceinstaller和进程安装程序。这就是我努力理解接下来要做什么的地方。 Installer class 我是否需要重写安装方法?我安装程序类的当前的代码是自动生成的,如下:

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 

我甚至可以添加CustomActionData值。该字符串决定了传递到用于收集输入的用户值的上下文对象中的内容。 param1是我的变量名称。 custom actions

我非常努力的安装程序代码...我想?

回答

0

要考虑的一个选择是使用第三方安装程序,如Installshield,它具有内置支持修改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 

在这样的情况下,我们总是将值写入注册表,使用户不必如果他们卸载重新输入或重新安装。

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

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

+0

感谢您的回复。阅读你的榜样,努力完全理解它。什么是变量Me.XMLDir? – Simon 2012-02-01 22:02:21

+0

该变量仅用于显示提取在customdata中传递的值。这是你将用来更新app.config。 – 2012-02-02 06:35:40

相关问题