现在的位置: 首页 > 综合 > 正文

用VS.NET制作WEB安装包

2012年08月11日 ⁄ 综合 ⁄ 共 1692字 ⁄ 字号 评论关闭
微软什么都想做,就连安装包制作工具也有,以前用Install shell9做过安装包,功能虽然很强大,脚本也好写,但是调试起来困难,界面非常也难调整,尤其在的分辨率的机器上。这几天本想用Install Shell9做安装包,无赖安装程序从服务器上删掉了,最好硬着头皮用.net了。如果不涉及到数据库的安装,其实用.NET做安装包也挺简单的。
1、在bin目录下添加dll文件的时,会把该dll文件引用的dll文件也加入进来,这点又点讨厌,如果添加互相引用的dll就会添加两次,编译时会报错,微软本意是好的,结果帮了倒忙,没办法,只好一个一个的把重复的删掉。
2、在属性窗口中可以更改IIS虚拟目录的属性,MSDN上有详细介绍,不多说了。
3、自定义用户界面必须放在安装地址界面之前
4、自述文件界面中的ReadmeFile文件必须是rtf格式的文件,文本文件虽然可以指定,但是安装时不能显示。搞不懂为什么。记得InstallShell9也有此问题。
5、再建一个C# windows工程项目。再在此工程项目中添加一个安装程序类,重载Install方法,

这里接受自定义界面传递过来的参数

public override void Install( IDictionary mySavedState ) 
 

   
base.Install( mySavedState ); 
    
   
string strDBType = "1" ;  //MSSQL 
   string strDBServer =this.Context.Parameters["dbServer"].ToString(); 
   
string strDBName = this.Context.Parameters["dbName"].ToString(); 
   
string strDBUser = this.Context.Parameters["dbUser"].ToString(); 
   
string strDBPwd = this.Context.Parameters["dbPass"].ToString(); 
     
   
try 
   

    
//Initial config file 
    System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly(); 
    
string sPath = asm.Location; 
    sPath 
= sPath.Substring(0,sPath.LastIndexOf("\\")+1); 
    InitialConfig config 
= new InitialConfig(sPath) ; 
    config.DBName 
= strDBName ; 
    config.DBPWD 
= strDBPwd ; 
    config.DBType 
= strDBType ; 
    config.DBUser 
= strDBUser ; 
    config.Server 
= strDBServer ; 
    config.Initial() ; 
   }
 
   
catch(Exception ex) 
   

    System.Windows.Forms.MessageBox.Show(
"Error Occurs During Initial Config File!\nError : " + ex.Message) ; 
     
   }
 
  }
 

6、在安装项目中的Web应用文件夹中添加项目输出,选择主输出。
7、在自定义操作中,在安装步骤下添加自定义操作
InstallerClass选择True
CustomActionData填入
/dbServer=[DBSERVER] /dbName=[DBNAME] /dbUser=[DBUSER] /dbPass=[DBPASS]
8.编译查错。微软的例子都是用VB写的,简单啊。

抱歉!评论已关闭.