ASP.NET应用程序结构
XCOPY部署
利用VS.NET的“复制项目”功能部署
使用VS.NET的“Web安装项目”部署
XCOPY部署
• .NET框架的主要目标之一就是简化部署,例
如支持XCOPY部署。
• 无干扰(Zero-Impact)安装:
– 编译器将标识符和元数据信息嵌入到了编译好的
模块之中,而CLR利用这些信息来装入程序集的
适当版本。标识符包含了装入和运行模块、查找
程序集引用的其他模块所需的所有信息。
– 系统不会因为修改注册表、配置组件而受到影
响;另外,无干扰安装也使得组件卸载操作不会
对系统产生任何意外的影响,卸载组件时只要从
特定的目录删除某些文件就可以了。
VS.NET提供的部署项目模板
1. 合并模块项目:将可能由多个应用程序共
享的组件打包。
2. 安装项目:为基于Windows的应用程序生
成安装程序。
3. Web 安装项目:为Web 应用程序生成安
装程序。
4. Cab 项目:创建压缩文件以下载到旧式
Web 浏览器。
安装编辑器介绍
• 文件系统编辑器:向安装软件包添加文件
• 注册表编辑器:为应用程序创建注册表项
• 文件类型编辑器:注册用户程序的具体文件扩展
名称
• 用户界面编辑器:添加和配置对话框,在安装程
序期间显式这些对话框
• 自定义操作编辑器:运行在安装和协载期间启动
定制程序
• 启动条件编辑器:可以规定对应用程序的要求
自动安装数据库的范例
public override void Install(System.Collections.IDictionary stateSaver)
{
//入口
strPass = this.Context.Parameters["strPass"];
AddDBTable("RequestSys");//RequestSys为数据库名称
}
private string GetSql(string strName)
{
try
{
//' Get the current assembly.
Assembly Asm = Assembly.GetExecutingAssembly();
// Resources are named using a fully qualified name
Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + "." + strName);
//Read the contents of the embedded file.
StreamReader reader= new StreamReader(strm);//,System.Text.Encoding.Unicode);
return reader.ReadToEnd();
}
catch
{
return null;
}
}
private void ExecuteSql(string DatabaseName , string Sql)
{
SqlConnection sqlConnection1 = new SqlConnection("user id=sa;password="+strPass+";database=master;server=(local)") ;
SqlCommand Command = new SqlCommand(Sql, sqlConnection1);
Command.Connection.Open();
Command.Connection.ChangeDatabase(DatabaseName);
try
{
Command.ExecuteNonQuery();
}
finally
{
// Finally, blocks are a great way to ensure that the connection
Command.Connection.Close();
}
}
protected void AddDBTable(string strDBName )
{
try
{
//Create the database.
ExecuteSql("master", "CREATE DATABASE " + strDBName);
// Create the tables.
ExecuteSql(strDBName, GetSql("sql.txt"));
}
catch
{
}
}
XCOPY部署
利用VS.NET的“复制项目”功能部署
使用VS.NET的“Web安装项目”部署
XCOPY部署
• .NET框架的主要目标之一就是简化部署,例
如支持XCOPY部署。
• 无干扰(Zero-Impact)安装:
– 编译器将标识符和元数据信息嵌入到了编译好的
模块之中,而CLR利用这些信息来装入程序集的
适当版本。标识符包含了装入和运行模块、查找
程序集引用的其他模块所需的所有信息。
– 系统不会因为修改注册表、配置组件而受到影
响;另外,无干扰安装也使得组件卸载操作不会
对系统产生任何意外的影响,卸载组件时只要从
特定的目录删除某些文件就可以了。
VS.NET提供的部署项目模板
1. 合并模块项目:将可能由多个应用程序共
享的组件打包。
2. 安装项目:为基于Windows的应用程序生
成安装程序。
3. Web 安装项目:为Web 应用程序生成安
装程序。
4. Cab 项目:创建压缩文件以下载到旧式
Web 浏览器。
安装编辑器介绍
• 文件系统编辑器:向安装软件包添加文件
• 注册表编辑器:为应用程序创建注册表项
• 文件类型编辑器:注册用户程序的具体文件扩展
名称
• 用户界面编辑器:添加和配置对话框,在安装程
序期间显式这些对话框
• 自定义操作编辑器:运行在安装和协载期间启动
定制程序
• 启动条件编辑器:可以规定对应用程序的要求
自动安装数据库的范例
public override void Install(System.Collections.IDictionary stateSaver)
{
//入口
strPass = this.Context.Parameters["strPass"];
AddDBTable("RequestSys");//RequestSys为数据库名称
}
private string GetSql(string strName)
{
try
{
//' Get the current assembly.
Assembly Asm = Assembly.GetExecutingAssembly();
// Resources are named using a fully qualified name
Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + "." + strName);
//Read the contents of the embedded file.
StreamReader reader= new StreamReader(strm);//,System.Text.Encoding.Unicode);
return reader.ReadToEnd();
}
catch
{
return null;
}
}
private void ExecuteSql(string DatabaseName , string Sql)
{
SqlConnection sqlConnection1 = new SqlConnection("user id=sa;password="+strPass+";database=master;server=(local)") ;
SqlCommand Command = new SqlCommand(Sql, sqlConnection1);
Command.Connection.Open();
Command.Connection.ChangeDatabase(DatabaseName);
try
{
Command.ExecuteNonQuery();
}
finally
{
// Finally, blocks are a great way to ensure that the connection
Command.Connection.Close();
}
}
protected void AddDBTable(string strDBName )
{
try
{
//Create the database.
ExecuteSql("master", "CREATE DATABASE " + strDBName);
// Create the tables.
ExecuteSql(strDBName, GetSql("sql.txt"));
}
catch
{
}
}