这是对我上一期提问的跟进:adding connection string during installation of vb.net project
这是我到目前为止的代码,但是行中的“配置”:
Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(exePath)
有一条蓝线,因此无法运行程序。我将C#代码转换为该代码,并出现蓝线。我在这里要做的是获取一个我可以用于连接字符串的字符串,该字符串将由app.config使用。
导入System.ComponentModel
导入System.Configuration.Install
Public Class 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
1}})...如果您还没有这样做,我会尝试添加Imports System.Configuration
语句
您是否在安装程序项目的System.Configuration
程序集中添加了reference? (对不起,我不记得它是否附带默认添加的程序集引用)