日期:2014-05-19  浏览次数:21070 次

打包 ,如何打包? C#.net(2.0)
给说个地方能找到答案也行!!

------解决方案--------------------
参考一下:

asp.net使用web安装程序 winform使用windows安装程序,如

------------------------------------------------
使用VS2005部署带有数据库的Web站点

使用VS2005制作安装包。
1. 在“新建项目”对话框的左侧树状图中选择“Other Project Types”-> “Setup and Deployment”节点,在右侧选择“Web Setup Project”。

2. 在Solution Explorer中在Solution上点右键,选择“Add”-> “Existing Web Site”,将存放编译好的Web网站的文件夹加入Solution中。

如果添加使用aspnet_compiler编译好的网站,有可能会出现下面的提示框,点击“是”就行。


3. 再添加一个新的“Class Library”,名称“CreateDB”,用以创建数据库的操作。


删除默认生成的“class1.cs”,在这个项目上点右键,选择“Add”-> “New Item”,在弹出的对话框中选择“Installer Class”,点击OK。

在类中添加如下代码:
private void ExecuteSql(string connectionString, string databaseName, string sql)
{
SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
try
{
sqlCommand.Connection.Open();
sqlCommand.Connection.ChangeDatabase(databaseName);
sqlCommand.ExecuteNonQuery();
}
catch (Exception exception)
{
throw exception;
}
finally
{
sqlCommand.Connection.Close();
}
}

public override void Install(System.Collections.IDictionary stateSaver)
{
string server = this.Context.Parameters[ "server "];
string database = this.Context.Parameters[ "dbname "];
string user = this.Context.Parameters[ "user "];
string password = this.Context.Parameters[ "pwd "];
string targetDir = this.Context.Parameters[ "targetdir "];

try
{
string connectionString = String.Format( "data source={0};user id={1};password={2};persist security info=false;packet size=4096 ",
server, user, password);

//create db
ExecuteSql(connectionString, "master ", "CREATE DATABASE " + database);

//set user
string setUserString = "sp_addlogin 'PrinteryERP ', 'PrinteryERP ', 'PrinteryERP ' ";
string setAccessString = "sp_grantdbaccess 'PrinteryERP ' ";
string setRole = "sp_addrolemember 'db_owner ', 'PrinteryERP ' ";

//create new user login
try
{
ExecuteSql(connectionString, "master ", setUserString);
}
catch { }

//set default database
try
{
ExecuteSql(connectionString, "PrinteryERP ", setAccessString);
}
catch { }

//set read role
try
{
ExecuteSql(connectionString, "PrinteryERP ", setRole);
}
catch { }

//create table,store produce......
Process osqlProcess = new Process();
osqlProcess.StartInfo.FileName = targetDir + "osql.exe ";
osqlProcess.StartInfo.Arguments = String.Format( " -U {0} -P {1} -S {2} -d {3} -i {4}createdb.sql ",
user, password, server, database, targetDir);
osqlProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
osqlProcess.Start();
osqlProcess.WaitForExit();
osqlProcess.Close();

//add data
osqlProcess.StartInfo.Arguments = String.Format( " -U {0} -P {1} -S {2} -d {3} -i {4}insertdata.sql ",
user, password, server, database, targetDir);
osqlProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
osqlProcess.Start();
osqlProcess.WaitForExit();
osqlProcess.Close();
}
catch (Exception exception)
{
throw exception;
}

try
{
string configFile = targetDir + "/Web.config ";
if (!File.Exists(configFile))
{
throw new InstallException( "没有找到配置文件。 ");