您的位置:首页 > 其它

使用VS的安装项目的总结

2009-12-24 15:31 591 查看
这几天一直在做一个Web程序的安装包,使用VS做安装程序需要注意的一些问题:

1. 关于两种Setup项目

VS 安装程序项目模板有一个Setup Project,还有一个是Web Setup Project。如果你的Web程序可以安装在C:/inetput/wwwroot下,那么使用Web Setup Project没什么问题,因为那是它的默认安装路径,且不能修改。这也是我放弃使用Web Setup Project的原因,因为客户要求程序文件要安装在C:/Program Files/ComanyName/ProductName/目录下。



2. 关于自定义Banner图片

安装向导界面的自定义Banner的图片大小是500x70,如果需要自定义的Banner,例如替换掉那个向导右上角默认的logo,可以用PS建一个500x70的图片,在图片右上角添加自己的logo。如果图片大小不是500x70会被强制压缩或拉伸为500x70,这样会影响图片显示质量。



3. 关于Custom Action

使用前面提到的Setup Project安装web程序,就要自己写custom action来创建IIS站点,虚拟目录。即使使用Web Setup Project默认的会帮你创建站点及虚拟目录,但是IIS虚拟目录的验证方式等使用的是默认配置(允许匿名登录),如果你的程序使用的是其他验证方式,还需要custom action来对IIS进行操作。



Custom Action 其实就是自定义的Class 只不过需要继承自System.Configuration.Install.Installer类
根据需要可重新该类的Install, Commit, Uninstall, Rollback等方法。这四个方法对应的就是Custom Action编辑器中的四种custom action类型
需要注意,custom action执行的时机:



Install

Custom actions placed under this node will be executed at the end of the install phase of installation, after all files have been installed.

Commit

Custom actions placed under this node will be executed at the end of the commit phase of installation, which occurs when the install phase has finished without errors.

Rollback

Custom actions placed under this node will be executed at the end of the rollback phase of installation, which is triggered when an installation error occurs.

Uninstall

Custom actions placed under this node will be executed at the end of the uninstall phase of installation, which occurs when an application is uninstalled.

因此,创建IIS虚拟目录的custom action应该是Install类型的,而安装结束后,打开应用程序首页的custom action应该是Commit类型。



4. 关于Custom Action的参数传递

安装向导与自定义的custom action直接的参数传递,例如用户在安装向导中配置的虚拟目录名称,可通过Custom Action Data
来传递。Setup项目中有许多内置的属性
,可直接作为参数使用。Web Setup 中还有自己特有的属性 TARGETVDIR, TARGETSITE 分别表示IIS虚拟目录名,IIS站点名。此外你还可以设置自定义的属性,并作为参数供custom action使用,例如用户在安装向导中输入的数据。



若要传递参数给Custom Action,需要在Custom Action编辑器中,选择你的Custom Action > 属性,在CustomActionData属性条码中配置,例如, /domain="[DOMAIN]" /dgroup="[DGROUP]"



其中 DOMAIN 及 DGROUP就是我的自定义向导界面中的两个输入框对应的属性值。



在Custom Action类中可通过如下代码,来获得用户输入值:



string domain = context.Parameters["domain"];

string domainGroup = context.Parameters["dgroup"];



5.关于web程序快捷方式



可是在安装文件中添加一个shortcut.cmd文件:Start http://localhost/myapp/default.aspx


然后就可以在VS中创建基于这个.cmd的快捷方式了。在VS2008安装项目的文件系统编辑器中,创建用户程序菜单的快捷方式,可以先右键那个.cmd文件,选择创建快捷方式,然后将该快捷方式拖到[用户程序菜单]下面。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: