【发布时间】:2011-01-05 04:20:53
【问题描述】:
我的解决方案中有 2 个项目
Windows 服务
其设置项目
我需要我的 ProjectInstaller : System.Configuration.Install.Installer 的 OnAfterInstall 方法从安装项目中获取 ProductName。我该怎么做?
【问题讨论】:
标签: c# .net visual-studio windows-installer setup-project
我的解决方案中有 2 个项目
Windows 服务
其设置项目
我需要我的 ProjectInstaller : System.Configuration.Install.Installer 的 OnAfterInstall 方法从安装项目中获取 ProductName。我该怎么做?
【问题讨论】:
标签: c# .net visual-studio windows-installer setup-project
在您的设置项目中,右键单击项目并选择查看 > 自定义操作。添加自定义操作。现在选择 Add Output,选择您的 Web 服务项目,然后单击 OK。
现在选择您的自定义操作并将CustomActionData 属性设置为包含类似/ProductName=[PRODUCTNAME] /whateveryouwant=[Whateveryouwant] 的内容(请注意,这些是键值对;即访问产品名称,ProductName 是键,值是@ 987654324@)。
请注意,CustomActionData 包含将传递给安装程序类的参数。 PRODUCTNAME 是与用户界面对话框中的输入控件关联的属性名称,因此在您的情况下,您将在安装程序中提示用户输入产品名称。所以标签是“产品名称”,对应的属性应该设置为PRODUCTNAME(显然你可以改变这个,但最需要注意的是UI属性名称必须与@中的属性名称相同987654328@) 让这个例子工作。
现在在您的安装程序类中,您可以通过以下方式获取产品名称
public override void Install(IDictionary stateSaver)
{
// If you need to debug this installer class, uncomment the line below
//System.Diagnostics.Debugger.Break();
string productName = Context.Parameters["ProductName"].Trim();
string whateveryouwant = Context.Parameters["whateveryouwant"].Trim();
}
请注意,我包含了注释代码 //System.Diagnostics.Debugger.Break();,您可以在其中添加注释,以便调试安装程序类。
希望这会有所帮助。
【讨论】:
Cannot evaluate expression because the code of the current method is optimized.