Web项目打包过程.docx
- 文档编号:11529485
- 上传时间:2023-03-18
- 格式:DOCX
- 页数:24
- 大小:1.36MB
Web项目打包过程.docx
《Web项目打包过程.docx》由会员分享,可在线阅读,更多相关《Web项目打包过程.docx(24页珍藏版)》请在冰豆网上搜索。
Web项目打包过程
1、在现有项目中添加“Web安装项目”如(图1);
(图1)
2、添加项目输出文件(图2、3、4);
(图2)
(图3)
(图4)
3、添加数据库文件(提示:
数据文件大小不能大于800M,否则数据文件不能加入安装文件中一起安装。
也可以放在指定目录下,但要修改安装类里数据库文件的路径)如(图5、6);
(图5)
(图6)
4、设置系统必备如(图7、8、9、10、11);
(图7)
(图8)
(提示:
选择.NETFramework最高版本)
(图9)
(提示:
选择WindowsInstaller最高版本)
(图10)
(图11)
5、选择启动条件(提示:
本机必须装至少为IIS5.1版本)如(图12、13);
(图12)
(图13)
6、添加许可协议(图14、15、16、17、18、19、20、21);
(图14)
(图15)
(图16)
(提示:
上移到“欢迎使用”下)
(图17)
(图18)
(图19)
(图20)
(图21)
7、设置数据库信息(图14、22、23、24、25、26)
(图22)
(提示:
上移到“许可协议”下)
(图23)
(图24)
(图25)
设置数据库连接参数信息(提示:
如果没有第四个编辑字段,则设置该字段为隐藏状态)如下
(图26)
8、添加安装类如(图27、28、29、30、31、32)
(图27)
(图28)
(图29)
(图30)
(图31)
(图32)
添加的代码如下:
usingSystem;
usingSystem.Collections;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Configuration.Install;
usingSystem.Linq;
usingSystem.Xml;
usingSystem.Diagnostics;
usingSystem.Data;
usingSystem.Data.SqlClient;
namespaceInstallDB
{
[RunInstaller(true)]
publicpartialclassInstaller:
System.Configuration.Install.Installer
{
publicInstaller()
{
InitializeComponent();
}
publicoverridevoidInstall(System.Collections.IDictionarystateSaver)
{
base.Install(stateSaver);
//参数名必须与用户界面的“文本框A”设置的参数必须一致
stringserver=this.Context.Parameters["server"];
stringuid=this.Context.Parameters["uid"];
stringpwd=this.Context.Parameters["pwd"];
stringpath=this.Context.Parameters["targetdir"];
stringDataName="GDKSHDB";//数据库名称
stringconnString="server="+server+";uid="+uid+";pwd="+pwd+";database="+DataName;
stringconnStr="server="+server+";uid="+uid+";pwd="+pwd+";database=master";
stringstrMdf=path+"fxFrame.mdf";//如果是文件大于800M,则必须指定目录,不能用path安装目录
stringstrLdf=path+"fxFrame_log.ldf";//
UpdateConConfig(connString,path+"web.config");
this.CreateDataBase(connStr,DataName,strMdf,strLdf);
}
///
///附加数据库
///
///
///
///
///
privatevoidCreateDataBase(stringconnStr,stringDataName,stringstrMdf,stringstrLdf)
{
Stringstr;
SqlConnectionmyConn=newSqlConnection(connStr);
str="EXECsp_attach_db@dbname='"+DataName+"',@filename1='"+strMdf+"',@filename2='"+strLdf+"'";
SqlCommandmyCommand=newSqlCommand(str,myConn);
myConn.Open();
myCommand.ExecuteNonQuery();
myConn.Close();
myConn.Dispose();
}
///
/// 修改Web项目web.config配置文件的值
///
/// 连接字符串名称
/// 连接字符串
/// 设定档路径及名称
publicstaticvoidUpdateConConfig(stringconString,stringconfigfilePath)
{
XmlDocumentxmlDoc=newXmlDocument();
//读取设定档
xmlDoc.Load(configfilePath);
//取得连接字符串的节点
XmlNodexmlNode=xmlDoc.SelectSingleNode("configuration/appSettings/add[@key='Connection']");
//修改连接字符串
xmlNode.Attributes["value"].InnerText=conString;
//保存
xmlDoc.Save(configfilePath);
}
}
}
9、添加安装输出如(图33、34、35、36、37、38、39)
(图33)
(图34)
(图35)
(图36)
(图37)
(图38)
(图39)
指定要传递到安装程序的自定义数据代码如下:
/server=[CUSTOMTEXTA1]/uid=[CUSTOMTEXTA2]/pwd=[CUSTOMTEXTA3]/targetdir="[TARGETDIR]\"(提示:
其中的空格必不可少)
10、配置项目如(图40、41);
(图40)
(图41)
11、重新生成解决方案,然后从WebSetup\Debug目录下拷出安装目录(WebSetup.msi)即可。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Web 项目 打包 过程