Custom installation properties when the project is packaged, such as database name, etc.

xiaoxiao2021-03-06  115

Project package summary

Implementation: Depending on the user-defined database name and other files installation, if IEWebControls

step:

Create a new project: Visual C # item, select the class library template, such as named MyInstall, add a new item below this item: Select the installer class (Installer1.cs), here I use the default name. This installation class library will implement the installation of the database and the installation of other files.

In Installer1.cs, we will rewrite the installation class: see Reference 1

Install Commit Rollback Uninstall

To achieve custom installations in the Install method:

First we have to get some user variables (the user does operation during installation, such as database management account, etc.)

We can get this.context.parameters ["DatabaseName"] for these variables; (DatabaseName "]; (will be set in the installation item)

Here we got five variables. Install the server, the specified database name, database administrator account, password. And database backup files.

Let's take a look at the specific code, very simple :)

Private void installdatebase ()

{

System.Reflection.Assembly ASM;

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

// system.io.fileinfo fileInfo = new system.io.fileinfo (asm.location);

// You can also get the currently installed directory, such as the wwwroot directory, MyWeb / Your installation engineering name .dll

// The following is a database line and command

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)) // does not exist new one

{

Directory.created ;; Curdir;

}

String msql = "restore database" DBNAME

"From disk = '" DIR @ "/ database / mydatabase.bak'"

"With move 'mydate_dat' to '" curdir @ "/" dbname ".mdf',"

"Move 'mydate_log' 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 ();

}

/ / Install TreeView

ProcessStartInfo PSI = New ProcessStartInfo ();

PSI.WorkingDirectory = DIR "// Database";

PSI.FileName = DIR @ "/ database / ieWebControls.msi";

psi.useshellexecute = true; // msi file, if EXE is not available

Process.start (PSI);

// Which brother helps look at it. The following code. It will be said to be run when executed, causing you to run when you install these controls. Be sure. It can be. However, the following code has a little better than the above code, the following process waits until the end of the end of the entire install method. And the above code is in actual operation, the entire installation is over. The work installed with TreeView has just begun. A little disagreeable

// system.diagnostics.process myproc = new system.diagnostics.process ();

// myproc.enableraisingevents = true;

//

// String file = dir @ "/ database / ieWebControls.msi";

//

// myproc.startinfo.useshellexecute = true;

// myproc.startinfo.filename = file;

// myproc.start ();

// myProc.waitForeXit (); // This method can be completed indefinitely until the process is completed, and the following code is executed // if (myProc.hasexited == True)

// {

// // myproc.kill ();

//

//}

}

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 Stateaver)

{

Base.unInstall (StateSaver);

// uninstallDatabase ();

}

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

{

Base.commit (StateSaver);

}

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

{

Base.rollback (statesaver);

}

Reference 1:

MS-help: //ms.vscc/ms.msdnvs.2052/vbCon/html/vbtskoverridingdefault.htm

MS-help: //ms.vscc/ms.msdnvs.2052/vsintro7/html/vxwlkwalkthroughusingcustomActionTOCREATEDATABASEDURINSTALLATION.HTM

Now let's add a new project below this project.

Install and deploy projects, select Web project templates, such as named WebSetup2.

Create a deployment project

On the File menu, select Add Project -> New Project.

In the Add Project dialog, select Install and Deploy Projects in the Project Type pane, then select "Web Installation item" in the Template pane. In the Name box, type WebSetup2. (I am default, didn't change. These statements are too lazy to play, copy, :))

In the Properties window, select the ProductName property and type myWebTest.

In the File System Editor, select Application Folder. On the "Operation" menu, select Add "-> Project Output.

In the Add Issue Output Group dialog, select the main output for the "MyInstall" project.

In the previous operation, add some files in your web project to the usual packaging. And some other package settings (product names, etc.), I will not say much.

We just join a database backup file here (MyDatabase.bak)

First open the WebSetup2 file system window, select the web application folder, add a folder below this folder to store the database, such as Database, copy the MyDatabase.bak file below this directory.

Now we have to add a window to install, used to enable the user to enter the database account. We can do it as long as we open the user interface window.

Create a custom installation dialog

Select the "WebSetup2" item in the Solution Explorer. Point "Editor" on the View menu and select User Interface. In the User Interface Editor, select the "Start" node under "Install". On the Actions menu, select Add Dialog.

Select the text box (a) dialog in the Add Dialog dialog box.

Select "Move" on the "Operation" menu. Repeat this step until the text box (a) dialog is on the "Install Folder" node.

In the Properties window, select the Bannertext property and type a custom database installation.

Select the BodyText property and type the custom database installation

Select Edit1Label attribute and type the server name:.

Select the Edit1Property property and type ServerName.

Select Edit2Label attribute and type the Create Database Name:.

Select the Edit2Property property and type DatabaseName.

Select the Edit3Label property and type the database administrator account:.

Select the Edit3Property property and type InstallAdmin.

Select the Edit4Label property and type the administrator password:. Installpassword

Select the Edit4Property property and type ServerName.

Create custom operations

Select the "WebSetup2" item in the Solution Explorer. Point "Editor" on the View menu and select Customize.

Select the "Install" node in the Custom Operation Editor. On the Actions menu, select Add Custom Action.

Double-click Application Folders in the "Select Project" dialog box.

Select "The main output is from the DBCUSTOMACTION" item.

In the "Properties" window, select CustomActionData property and type / InstallPassword = [INSTALLPASSWORD] / InStallAdmin = [INSTALLADMIN] / ServerName = [SERVERNAME] / DataBaseName = [DATABASENAME] / dir = "[TARGETDIR] /" Note that the various users of There is space between space. Such as / aaa = [fdfad] / bFFF = [fdafdfd]

Select "Generate WebSetup2" on the Generation menu.

The above CustomActionData will be referenced in the installation class. Note that there must be space between each one.

/ DIR = ["Targetdir"], take the final installed web directory

This is over this project package.

转载请注明原文地址:https://www.9cbs.com/read-126468.html

New Post(0)