【发布时间】:2018-01-19 05:57:38
【问题描述】:
我已在 InstallerSetup.cs 中正确覆盖提交我不想将用户输入的值写入 app.config,而是我想传递字符串 Context.Parameters["TESTPARAMETER"];加载函数时到 form1.cs 中的另一个类。我试过string test = InstallerSetup.Context.Parameters["TESTPARAMETER"];
但获取 InstallerSetup.Context 为空。请帮忙。
InstallerSetup.cs
public static string SQLSERVERNAME = "";
public static string HMSTENANTDB;
public static string SQLLOGIN;
public static string SQLPASSWORD;
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
try
{
SQLSERVERNAME = Context.Parameters["SQLSERVERNAME"];
HMSTENANTDB = Context.Parameters["HMSTENANTDB"];
SQLLOGIN = Context.Parameters["SQLLOGIN"];
SQLPASSWORD = Context.Parameters["SQLPASSWORD"];
}
catch (Exception e)
{
MessageBox.Show("Failed to update the application configuration file : " + e.Message);
base.Rollback(savedState);
}
}
from1.cs
InstallerSetup InsSetup = new InstallerSetup();
string Vsqlserver = InsSetup.Installers.Count.ToString();
string Vtenant = "";
if (InsSetup.Context != null)
{
Vtenant = InsSetup.Context.Parameters["HMSTENANTDB"];
}
else
{
Vtenant = "context is null";
}
【问题讨论】:
-
您似乎正在使用 Visual Studio 安装项目,因此您需要确认您已将其添加为自定义操作,并显示如何将这些参数传递给自定义操作并说明您从何处获得值来自。
-
在文本框中输入用户界面参数“HMSTENANTDB”。 “HMSTENANTDB”在自定义操作 Commit() 中得到恢复。在 form1.cs 中,“HMSTENANTDB”应该被恢复。我试过 Vtenant = InsSetup.Context.Parameters["HMSTENANTDB"];但 Vtenant 为空。
-
使这项工作发挥作用的一件事是在调用自定义操作时在 CustomActionData 中传递参数,这就是我所说的“将这些参数传递给自定义操作”的意思,这种类型的添加信息应该被添加为问题的编辑,但仍然没有足够的数据来解决这个问题。您实际上已经在 setup 项目中添加了自定义操作,这也不是很明显,我不是指代码,我指的是对它的调用。
-
//将这些参数传递给自定义操作....................... ..... SQLSERVERNAME = Context.Parameters["SQLSERVERNAME"]; HMSTENANTDB = Context.Parameters["HMSTENANTDB"]; SQLLOGIN = Context.Parameters["SQLLOGIN"]; SQLPASSWORD = Context.Parameters["SQLPASSWORD"]; //................我的自定义操作中只有这 4 行
标签: c# parameters windows-installer visual-studio-setup-proje