0

的過程中添加連接字符串,這是一個跟進我的最後一個問題是關於:adding connection string during installation of vb.net project安裝vb.net

這是代碼,我有這麼遠,但在該行的「配置」:

Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(exePath)

有一條藍線,我無法運行該程序,因爲它。我將C#代碼轉換爲該代碼,並出現藍線。我在這裏要做的是獲得一個字符串,我可以使用它將被app.config使用的連接字符串。

進口System.ComponentModel

進口System.Configuration.Install

公共類InstallerClass

Public Sub New() 
    MyBase.New() 


    InitializeComponent() 

End Sub 


<RunInstaller(True)> _ 
Partial Public Class MyInstaller 
    Inherits Installer 


    Partial Public Class MyInstaller 
     Inherits Installer 


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


      MyBase.Install(stateSaver) 

      Dim targetDirectory As String = Context.Parameters("targetdir") 

      Dim param1 As String = Context.Parameters("Param1") 

      Dim param2 As String = Context.Parameters("Param2") 

      Dim param3 As String = Context.Parameters("Param3") 


      Dim exePath As String = String.Format("{0}MyWindowsFormsApplication.exe", targetDirectory) 

      Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(exePath) 

      config.AppSettings.Settings("Param1").Value = param1 

      config.AppSettings.Settings("Param2").Value = param2 

      config.AppSettings.Settings("Param3").Value = param3 

      config.Save() 

     End Sub 

    End Class 




End Class 

末級

+0

我建議您使用新內容編輯您的原始問題。 –

回答

0

我不知道這是它,但有些東西我已經注意到您發佈的代碼:

  • ConfigurationManager來自System.Configuration命名空間,一樣的Configuration類,但你似乎並不有Imports System.Configuration在你的代碼(僅Imports System.Configuration.Install)......我會嘗試加入Imports System.Configuration聲明,如果你沒有這個已

  • 您是否在安裝程序項目中將reference添加到System.Configuration程序集中? (對不起,我不記得是否在默認情況下添加了此組裝參考)

+0

感謝@nkvu,我在參考中添加了System.Configuration程序集,藍線消失了。我會試着弄清楚現在其他方面的工作。謝謝 – Chloe