问题
this is a follow up for my last question which is on: adding connection string during installation of vb.net project
this is the code that I have so far but the "Configuration" in the line:
Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(exePath)
has a blue line and I can't run the program because of it. I converted the C# code to that one and the blue line appears. what I'm trying to do here is to get the a string that I can use for the connection string which will be used by the app.config.
Imports System.ComponentModel
Imports 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
End Class
回答1:
I don't know if this is it but some things I have noticed from the code you have posted:
ConfigurationManager comes from the
System.Configuration
namespace, as does the Configuration class but you don't seem to haveImports System.Configuration
in your code (onlyImports System.Configuration.Install
)...I would try adding aImports System.Configuration
statement if you don't have this alreadyHave you added a reference to the
System.Configuration
assembly in your installer project? (Sorry, I don't remember if it comes with this assembly reference added by default)
来源:https://stackoverflow.com/questions/15684897/adding-connection-string-during-installation-of-vb-net