2012-02-01 12 views
0

Windowsサービス用のmsiインストールを作成しようとしています。 msiを作成する理由は、意図したユーザーができるだけ小さな介入で迅速にサービスをインストールできるようにするためです。MSIインストール中にApp.configアプリケーション設定を構成するvb.net

msiとしてインストールするサービスを取得できますが、msiがインストールされているときにユーザーが定義する必要がある変数がコード内にあります。ユーザーから要求される変数は、自分のサービスが作成するxmlファイルを作成するファイルパスです。

私は、app.configアプリケーション設定で、xmlファイルを書き込むファイルパスを含むように設定できたと考えました。しかし、私はこれを行うには苦労していると私はそれを行うための最善の方法はないかわからない?

実行可能ファイルが含まれているセットアッププロジェクトがあり、ユーザーからの1つの変数を含むテキストボックスがあります。 setup project

私のサービスインストーラとプロセスインストーラを含むインストーラクラスがあります。これは私が次に何をする必要があるかを理解するために苦労しているところです。 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

考慮すべき1つのオプションは、InstallShieldなどの設定ファイルなどのxml構成ファイルの変更をサポートする組み込みのインストーラーを使用することです。

ただし、自分でロールする場合は、インストールメソッドをオーバーライドする必要があります。 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

+0

変数は、customdataで渡された値を抽出することを示しています。これはapp.configの更新に使用するものです。 –

関連する問題