In this article I am going to demonstrate how to customize your MSI install to prompt the user for some information and then pass this information to an installer class.  This can
be useful when needing to do something during an install based on the user input. 



There are two key parts to this process the first is the addition of a custom user interface dialog and the second is passing whatever information is entered into the new user interface  to the installer class in order to do something with this information
during installation.

For the sake of simplicity this MSI is going to install an assembly called MySampleAssembly and inside the project we will add an installer class that will take the information the
user enters via the newly added user interface and place this information into the event log.  (Once you get the information into the installer class you can do anything you want with it, we are placing it in the event log only to prove that the information
was successfully passed in)

This article assumes some basic understanding of MSI projects, more information can be found on at 



http://www.c-sharpcorner.com/Code/2002/July/BuildnDeployUsingVSNet.asp

Part One Adding a New User Interface



1. First start a new Set-up project.

2. Next we need to make the modifications to the default user interface settings.  Navigate to the view/Editor/User Interface as shown below.

This brings up the User Interface editor and displays the default MSI user interface.  You can see that this is broken up into a couple of different sections that are common to all
MSI setups.

3. Next you need to right click on the Start node of the tree view and choose the Add Dialog menu item as shown below:

This will bring up the Add Dialog menu displaying all of the various user dialogs you can add to the msi.  We are going to add 3 radio buttons to the default user interface that
prompts the user for his/her input in regards to what environment the application is being deploy into Dev, Test, or Prod.   This is common issue when building deployment scripts, as we may need to do different things based on the environment we are deploying
too.  Select the Radio Buttons (3 buttons) icon as shown below:

4. An icon representing the radio buttons user dialog should now be displayed in the user interface editor.   By right clicking on this icon and choosing the properties menu item
the default properties will be displayed for this user interface item.  Modify all the properties to look like the following:

An important thing to notice is the ButtonProperty that is currently set at BUTTON3.   This is the name of our newly added user interface item and ultimately the variable that holds
the value that the user has entered when the MSI is run.  In our case the screen we added contains three radio buttons and based on what the user chooses at the time of the install the BUTTON3 variable will hold a 1,2 or 3.

Part Two: Passing Information to the Installer Class.

5. Next we need to create a sample assembly and include an installer class in the project that will accept the information input by the user and do something with it.  The addition
of the installer class is the same as an earlier article I wrote with one key difference.  If you are not familiar with installer classed you can read an earlier article located here:

http://www.c-sharpcorner.com/Code/2002/July/UseInstClasses.asp

Creating The Sample Assembly

6. Create a simple assembly and call it mySampleAssembly.

7. Next right click on project name in the solution explorer and choose add new item and double click on the installer class icon.

8. Now navigate to the installer class and look at the code that is generated for you automatically. You need to override the Install function by adding the following code.



public override void Install(System.Collections.IDictionary
stateSaver)

{

string myPassedInValue=this.Context.Parameters["TEST"];

//1=DEV 2=TEST 3= PROD

System.Diagnostics.EventLog.WriteEntry

("Button3 value", myPassedInValue); 

}

This does nothing but get a value from the parameter named "TEST" and put it into the eventlog.

For the sake of simplicity leave all the other classes in the MySampleApp assembly alone and compile the assembly.  You will also need to add a using

9.  We now need to add this newly compiled assembly to our MSI project that we were working on earlier.  Go back to the MSI project we were working on earlier and click on the View/Editor/File
System, which will bring up the file system editor in the msi project.  Right click on the application folder and choose add/File as shown below.

Navigate to the MySampleApp assembly we just made and add it to the msi project.

10.  Next choose the View / Editor / Custom Actions menu item, this will bring up the custom action dialog menu as shown below.

Highlight the install folder and right click on the folder and choose Add Custom Action as shown below.

Navigate to the assembly we just added to the installer class and click ok as shown here.

This tells the MSI project to run any installer classes that is in the MySampleAssembly assembly.

Finally, choose the properties of the custom action and modify the properties as shown below.

Notice in the CustomActionData that we are placing a /TEST=[BUTTON3].  This tells the installer class to pass the value of the Button3 user interface object to the installer class
in a parameter named TEST.  In this particular case it is a 1, 2, or 3 that will be passed to the installer class but it could be anything from a database name to a server name that is passed to the installer class.

11.   Finally, compile and run the msi eventually you should see the new user interface and will place a 1, 2, or 3 into the event log based which radio button you chose.

In this article I demonstrated how to add a custom dialog to an MSI and take the information received from this newly added dialog and pass it into an installer class.  This can
be useful when creating MSI's that need to behave differently based on some user input.

Customize User Interfaces and Pass User Input to Installer Classes的更多相关文章

  1. MyBatis(3.2.3) - Passing multiple input parameters

    MyBatis's mapped statements have the parameterType attribute to specify the type of input parameter. ...

  2. ie8下修改input的type属性报错

    摘要: 现在有一个需求如图所示,当用户勾选显示明文复选框时,要以明文显示用户输入的密码,去掉勾选时要变回密文,刚开始想到的就是修改输入框的type来决定显示明文还是密文,使用jQuery的attr来做 ...

  3. Professional C# 6 and .NET Core 1.0 - Chapter 41 ASP.NET MVC

    What's In This Chapter? Features of ASP.NET MVC 6 Routing Creating Controllers Creating Views Valida ...

  4. C++ Core Guidelines

    C++ Core Guidelines September 9, 2015 Editors: Bjarne Stroustrup Herb Sutter This document is a very ...

  5. Getting Started with Django Rest Framework and AngularJS

    转载自:http://blog.kevinastone.com/getting-started-with-django-rest-framework-and-angularjs.html A ReST ...

  6. 【Python】Django RestFramework资料

    A ReSTful API is becoming a standard component of any modern web application.  The Django Rest Frame ...

  7. Effective Python2 读书笔记3

    Item 22: Prefer Helper Classes Over Bookkeeping with Dictionaries and Tuples For example, say you wa ...

  8. .net Framework Class Library(FCL)

    from:http://msdn.microsoft.com/en-us/library/ms229335.aspx 我们平时在VS.net里引用的那些类库就是从这里来的 The .NET Frame ...

  9. Using PL/SQL APIs as Web Services

    Overview Oracle E-Business Suite Integrated SOA Gateway allows you to use PL/SQL application program ...

随机推荐

  1. 洛谷——P1743 矩阵 III

    P1743 矩阵 III 题目背景 usqwedf 改编系列题. 题目描述 给定一个n*m的矩阵,问从左上角走到右下角有多少条路径. 输入输出格式 输入格式: 一行两个正整数 n,m 输出格式: 路径 ...

  2. python3.6下安装结巴分词需要注意的地方

    近期,在安装结巴分词的时候遇到一些问题,纠结了好一阵,跟大家分享下,希望能有所帮助.先说下安装环境: windows7, 64位系统 python3.6,python3.5在结巴分词的官方github ...

  3. Spring 概念详解

    一.Spring的IoC(Inversion of Control). 这是Spring中得有特点的一部份.IoC又被翻译成“控制反转”,也不知道是谁翻译得这么别扭,感觉很深奥的词.其实,原理很简单, ...

  4. [BZOJ 1857] 传送带

    Link: BZOJ 1857 传送门 Solution: 首先中间的两个拐点$C,D$肯定都在传送带$A,B$上 接下来感性发现固定点A/C,另一个点C/D时间随位置的变化为单峰函数 这样就是三分套 ...

  5. AGC 016 C - +/- Rectangle

    题面在这里! 结合了贪心的构造真是妙啊2333 一开始推式子发现 权是被多少个w*h矩形覆盖到的时候 带权和 <0 ,权都是1的时候带权和 >0,也就是说被矩形覆盖的多的我们要让它尽量小. ...

  6. 【模拟退火】poj2069 Super Star

    题意:让你求空间内n个点的最小覆盖球. 模拟退火随机走的时候主要有这几种走法:①随机旋转角度. ②直接不随机,往最远的点的方向走,仅仅在尝试接受解的时候用概率.(最小圆/球覆盖时常用) ③往所有点的方 ...

  7. 使用 Google Code Prettify 实现代码高亮

    今天这篇文章主要讲述使用 google-code-prettify 来实现代码的高亮显示,以前我使用 highlight.js 来实现文章中代码的高亮显示. prettify 非常小巧且配置简单,使用 ...

  8. 可添加头部尾部RecyclerView,很帅哦~

    WrapRecyclerView 是一个可以添加头部和尾部的RecyclerView,并且提供了一个 WrapAdapter, 它可以让你轻松为 RecyclerView 添加头部和尾部.   示例中 ...

  9. [Linux] Proc 文件系统

    转载自:http://linux.chinaunix.net/doc/2004-10-05/16.shtml#324lfindex0 目录: /proc --- 一个虚拟文件系统 加载 proc 文件 ...

  10. Java 定时任务 & 任务调度

    任务调度是指基于 给定时间点,给定时间间隔 或者 给定执行次数 自动执行任务. 方式1:通过 Thread 来实现 例如如下的代码,可以每隔 1000 毫秒做一次打印操作. public class ...