在安装vb.net期间添加连接字符串 [英] adding connection string during installation of vb.net
问题描述
这是我最后一个问题的后续跟进:在安装vb.net项目期间添加连接字符串
这是我到目前为止的代码,但配置in the line:
Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(exePath)
我不能运行程序,因为它。我将C#代码转换为那个,出现蓝线。我想在这里做的是获取一个字符串,我可以使用的连接字符串将由app.config使用。
导入系统。 ComponentModel
导入System.Configuration.Install
公共类InstallerClass
Public Sub New()
MyBase.New()
InitializeComponent()
$ b b End Sub
< RunInstaller(True)> _
部分公共类MyInstaller
继承安装程序
部分公共类MyInstaller
继承安装程序
覆盖子安装(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。设置(Param2)。Value = param2
config.AppSettings.Settings(Param3)。Value = param3
config.Save()
b $ b End Sub
结束类
结束类
结束类
是我注意到的一些事情从你发布的代码:
-
ConfigurationManager
来自System.Configuration
命名空间,配置
类,但您似乎没有Imports System.Configuration
(只有Imports System.Configuration.Install
)...我会尝试添加一个//msdn.microsoft.com/en-us/library/vstudio/wkze6zky%28v=vs.100%29.aspxrel =nofollow>参考到
System.Configuration
在安装程序项目中的程序集? (对不起,我不记得它是否与这个程序集引用默认添加)
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
I don't know if this is it but some things I have noticed from the code you have posted:
ConfigurationManager
comes from theSystem.Configuration
namespace, as does theConfiguration
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)
这篇关于在安装vb.net期间添加连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!