Web Project Installation

Source: Internet
Author: User

1. How to resend the. Net Framework

Http://www.microsoft.com/china/MSDN/library/netFramework/netframework/Nfdnnetdepvsredistdeploy1_1.mspx? Mfr = true

 

 

 

2. How to install a database

Create a new project: visual C # project, select the class library template, for example, the name is myInstall, add a new item under this project: select the installation program class (Installer1.cs), here I use the default name. This installation class library will install databases and other files.

In installer1.cs, We will rewrite the installation class method: see reference 1.

Install Commit Rollback Uninstall

To implement custom installation in the install method:

First, we need to get some user variables (user operations during installation, such as database management accounts)

For these variables, we can use the Context Environment to obtain this. Context. Parameters ["DataBaseName"]; (this will be set in the installation project)

Here we get a total of five variables.

Database Name

ServerName

Database Administrator Account InStallAdmin

Password InstallPassword

Database Backup File Dir

Let's take a look at the specific code, which is very simple.

Private void InstallDateBase ()

{

// System. Reflection. Assembly Asm;

// ASM = system. reflection. Assembly. getexecutingassembly ();

// System. Io. fileinfo = new system. Io. fileinfo (ASM. Location );

// You can also obtain the currently installed directory, for example, myweb \ your installation project name. dll under the wwwroot directory

// The following are database connections and commands

Sqlconnection sqlconnection1 = new sqlconnection ();

String dbname = This. Context. Parameters ["databasename"];

String dbserver = This. Context. Parameters ["servername"];

String dbuser = This. Context. Parameters ["installadmin"];

String dbkey = This. Context. Parameters ["installpassword"];

String dir = This. Context. Parameters ["dir"];

Streamwriter Ss = new streamwriter (@ "C: \ aaa.txt", true );

SS. writeline ("Data Source =" + dbname + "; database = Master; uid =" + dbuser + "; Password =" + dbkey );

SS. Close ();

String CONSTR = "data source =" + DBServer + "; database = master; uid =" + DBUser + "; password =" + DBKey;

SqlConnection1.ConnectionString = CONSTR;

// The database will be installed under system32

String CurDir = Directory. GetCurrentDirectory () + @ "\ TestData \ database ";

If (! Directory. Exists (CurDir) // creates

{

Directory. CreateDirectory (CurDir );

}

String MSQL = "restore database" + DBName +

"From disk = '" + dir + @ "\ database \ myDataBase. bak'" +

"With move 'mydate _ dat (the name of the mdf Suffix in the backup database file) 'TO'" + CurDir + @ "\" + DBName + ". mdf ', "+

"MOVE 'mydate _ log (the name of the ldf Suffix in the backup database file) 'TO'" + CurDir + @ "\" + DBName + ". ldf '";

SqlCommand cmd = new SqlCommand (MSQL, sqlConnection1 );

Cmd. Connection. Open ();

Cmd. ExecuteNonQuery ();

Cmd. Connection. Close ();

If (sqlConnection1.State = ConnectionState. Open)

{

SqlConnection1.Close ();

}

}

Public override void Install (System. Collections. IDictionary stateSaver)

{

Try

{

Base. Install (stateSaver );

This. InstallDateBase (); // call the above method

}

Catch
{

Throw;

}

}

Public override void uninstall (system. Collections. idictionary statesaver)

{

Base. Uninstall (statesaver );

}

Public override void commit (system. Collections. idictionary statesaver)

{

Base. Commit (statesaver );

}

 

Public override void rollback (system. Collections. idictionary statesaver)

{

Base. rollback (statesaver );

}

 

1. Create a deployment project

On the File menu, choose add project> new project ".
In the Add project dialog box, select "Install and deploy Project" in the "project type" pane, and select "Web Installation Project" in the "template" pane ". In the "name" box, type websetup2. (I am the default one. I didn't change it. These statements are too lazy to be typed and copied ,:))
In the Properties window, select the productname attribute and type mywebtest.
In the file system Editor, select "application folder ". On the "operations" menu, choose "add"> "project output ".
In the "add project output group" dialog box, select the primary output for the "myinstall" project.
 

The preceding operations are the same as general packaging. Add some files in your web project. And some other packaging settings (product name, etc.

Here we only need to add a database backup file (mydatabase. Bak)

First open the file system Window of websetup2, select the web application folder, and add a folder under this folder to store the database, such as database, and then copy the mydatabase. Bak file to this directory.

Now we need to add a installation window for users to enter database accounts. You only need to open the user interface window to perform operations.

 

Create custom installation dialog box

Select the "websetup2" project in Solution Explorer. On the "View" menu, point to "Editor" and select "User Interface ".
In the User Interface Editor, select the "Start" node under "installation. On the "operations" menu, select "add dialog box ".
In the Add dialog box, select the text box (A) dialog box.
On the "operations" menu, select "Move Up ". Repeat this step until the "text box (A)" dialog box is located on the "Install Folder" node.
In the "properties" window, select the BannerText attribute and type custom database installation
Select the BodyText attribute and type custom database installation
Select the Edit1Label attribute and enter the server name :.
Select the Edit1Property property and type SERVERNAME.
Select the Edit2Label attribute and type "Create Database Name :.
Select the Edit2Property property and type DATABASENAME.
Select the Edit3Label attribute and enter the database administrator account :.
Select the Edit3Property property and type INSTALLADMIN.
Select the Edit4Label attribute and enter the administrator password :.
Select the Edit4Property property and type INSTALLPASSWORD.
 

Create a custom operation

Select the "websetup2" project in Solution Explorer. On the "View" menu, point to "Editor" and select "Custom operations ".
Select the "Install" node in the Custom operation editor. On the "operations" menu, select "add custom operation ".
In the "select project items" dialog box, double-click "application folder ".
Select "add output ";
Select "main output from DBCustomAction (activity.
In the "properties" window, select CustomActionData and type/InstallPassword = [INSTALLPASSWORD]

/InStallAdmin = [INSTALLADMIN]

/ServerName = [SERVERNAME]

/DataBaseName = [DATABASENAME]/dir = "[TARGETDIR] \"
Note that there are spaces between user data. For example,/aaa = [fdfad]/bfff = [fdafdfd]

On the "generate" menu, select "generate websetup2 ".
The above customActionData will be referenced in the installation class. Note that there must be spaces between each other.

/Dir = ["TARGETDIR"], which is the final installed WEB directory

The package of this project has ended.

3. How to install additional files

For example, www \ webctrl_client and www \ aspnet_client

Add a special folder to the file system on the target computer> Web custom folder

 

Set the folder properties as follows and drag the directory to the folder.

 

4. How to set the installation Properties

 

5. files required for Installation

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.