这是我最后一个问题的跟进:在安装 vb.net 项目期间添加连接字符串
这是我到目前为止的代码,但行中的“配置”:
将配置调暗为配置 = 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
结束类