Asp.net| Packing
Use the MSDN Webcasts asp.net program deployment and a Lee Honggen article, and then add your own experience to the entire SQL and asp.net (vb.net) package of the whole process of writing.
I. Preparation of the necessary documents
1. SQL script files to generate the tables and stored procedures needed in the future installation process, and so on;
After the build, it is temporarily named Db.sql (note case)
2.LISENCEFILE.RTF installation files, because my system is personal, and free, so did not do. This is to be used later.
Two. Create a deployment project within your existing project:
1. On the File menu, point to Add Item, and then select New Project. (Figure 1-2)
2. In the Add New Project dialog box, select Install and deploy projects in the Project Types pane, and then select Web Setup Project in the Templates pane. Type Test Installer in the Name box. (Figure 1-3)
3. Click OK to close the dialog box.
4. The project is added to Solution Explorer and the File System Editor opens.
5. In the Properties window, select the ProductName property and type Gcrm.
(1-2)
(Figure 1-3) The role of other projects can be referred to webcast
Three. Add the output of the Vbnettest project to the deployment project (if your virtual directory is sqlandaspnet)
1. In the File System Editor, select Web Application Folder. On the Action menu, point to Add, and then select Project Output. (Figure 1-4)
2. In the Add Project Output Group dialog box, select Sqlandaspnet in the Project Drop-down list.
3. Click OK to close the dialog box.
4. Select the primary output and content files groups from the list, and then click OK. (Figure 1-5)
(Figure 1-4)
(Fig. 1-5) Other functions can refer to webcast, the source file is the file for all the purposes
Four.
To create a Custom installation dialog box
1. Select the "Test Installer" project in Solution Explorer. On the View menu, point to Editor, and then select User interface. (Figure 1-6)
2. In the User Interface Editor, select the startup node under install. On the Action menu, select Add dialog box.
3. In the Add Dialog dialog box, select the License Agreement dialog box, and then click OK to close the dialog box. (Note: I did not add, because temporarily I still do not need, need to add a bit OH)
4. In the Add Dialog dialog box, select the text Box (A) dialog box, and then click OK to close the dialog box. (Figure 1-7)
5. On the Action menu, select Move Up. Repeat this step until the text box (A) dialog box is above the installation folders node.
6. In the Properties window, select the BannerText property and type: Install the database ...
7. Select the BodyText property and type: Setup will install the database on the target machine.
8. Select the Edit1Label property and type: Database name:.
9. Select the Edit1Property property and type CUSTOMTEXTA1.
10. Select the Edit1Value property and type: Gscrm.
11. Select the Edit2label property and type: Server name:.
12. Select the Edit2property property and type CUSTOMTEXTA2.
13. Select the Edit2value property and type: (local).
14. Select the Edit3label property and type: User name:.
15. Select the Edit3value property and type: SA.
16. Select the Edit3property property and type CUSTOMTEXTA3.
17. Select the Edit4label property and type: password:.
18. Select the Edit4property property and type CUSTOMTEXTA4.
19. Select Edit2Visible, edit3visible, and set them to False. (Figure 1-8)
(Figure 1-7)
(Figure 1-8)
(v). Create a custom Action
1. In Solution Explorer, select the Test Installer project. On the View menu, point to Editor, and then select Custom Actions. (Figure 1-9)
2. Select the Install node in the Custom Action Editor. On the Action menu, select Add Custom action.
3. In the Select Item in Project dialog box, double-click Application Folder.
4. Select the main output from DBCustomAction (active) Item, and then click OK to close the dialog box.
5. In the Properties window, select the CustomActionData property and type/dbname=[customtexta1]/server=[customtexta2]/user=[customtexta3/pwd=[ CUSTOMTEXTA4]/targetdir= "[targetdir]\". (Figure 1-10)
Attached/targetdir= "[targetdir]\" is the target path after installation, in order to obtain the installed path in the DBCustomAction class, we set this parameter.
In addition, the installed path can also be obtained by reflection:
Dim Asm as System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly
MsgBox ("Asm.location")
(Figure 1-9)
(Figure 1-10)
Oh, already much better, the rest is the key step, I spent a lot of time studying.
(vi) Create an installer class
1. On the File menu, point to New, and then select Project.
2. In the New Project dialog box, select Visual Basic project in the Project Types pane, and then select Class Library in the Templates pane. In the Name box, type DBCustomAction.
3. Click Open to close the dialog box.
4. From the Project menu, choose Add New Item.
5. In the Add New Item dialog box, select Setup class. In the Name box, type DBCustomAction.
6. Click OK to close the dialog box. (Figure 1-11,1-12)
Note: This is the original project to create a simple installation file on it.
(Figure 1-11)
Added effect chart:
(Figure 1-12) The SQL file here is to be added
Seven
Add files
1. Add the script file Db.sql generated by SQL Server to the "Test Installer" project (Figure 1-12)
2. Add the installation file Lisencefile.rtf to the "Test Installer" project
3. In the User Interface Editor, select the license agreement and set the Lisencefile property to Lisencefile.rtf file
(eight)
The code is the most important part of the entire deployment.
Add code to the Installer class, DBCustomAction.vb class
Imports system.componentmodelimports System.Configuration.Installimports system.ioimports system.reflection Public Class dbcustomactionclass dbcustomactioninherits System.Configuration.Install.Installer Component Designer generated code #region " Component Designer generated code "public Sub New () Sub New () MyBase.New ()" The call is required by the Component Designer InitializeComponent () ' in InitializeComponent () Add any initialization end Sub ' Installer after the call to clean up the list of components. Protected Overloads Overrides Sub Dispose () Sub Dispose (ByVal disposing as Boolean) if disposing thenif not (components is N othing) Thencomponents.dispose () End IfEnd Ifmybase.dispose (disposing) End SubPrivate components as System.ComponentModel.IContainer Private Sub InitializeComponent () Sub InitializeComponent () End sub#end Region ' Execute SQL Statement Private Sub ExecuteSQL () Sub ExecuteSQL (ByVal conn As String, ByVal DatabaseName as String, ByVal Sql As String) Dim mySql Connection as New Sqlclient.sqlconnection (conn) Dim Command As New Sqlclient.sqlcommand (SQL, mysqlconnection) Command.connection.open () Command.connection.changedatAbase (DatabaseName) trycommand.executenonquery () finally ' close Connectioncommand.connection.close () End Tryend SubPublic Overrides Sub Install () Sub Install (ByVal statesaver as System.Collections.IDictionary) Mybase.install ( statesaver) '------------------------build database-------------------------------------------------Trydim connstr as String = String.Format ("Data source={0};user id={1};p assword={2};p ersist security Info=false;packet size=4096", Me.Context.Parameters.Item ("server"), Me.Context.Parameters.Item ("user"), Me.Context.Parameters.Item ("pwd")) ' Establish database ExecuteSQL (connstr, "Master", "CREATE DATABASE" + Me.Context.Parameters.Item ("dbname") according to the database name entered) Call osql Execute script Dim sqlprocess as New System.Diagnostics.Processsqlprocess.startinfo.filename = "Osql.exe" Sqlprocess.startinfo.arguments = String.Format ("-u {0}-p {1}-D {2}-I {3}db.sql", Me.Context.Parameters.Item ("user"), M E.context.parameters.item ("pwd"), Me.Context.Parameters.Item ("dbname"), Me.Context.Parameters.Item ("Targetdir")) Sqlprocess.sTartinfo.windowstyle = ProcessWindowStyle.Hiddensqlprocess.start () sqlprocess.waitforexit () ' Waits for the execution of Sqlprocess.close ( ' Delete script file Dim sqlfileinfo As New System.IO.FileInfo (String.Format ("{0}db.sql", Me.Context.Parameters.Item ("Targetdir") ) if Sqlfileinfo.exists thensqlfileinfo.delete () end Ifcatch ex as Exceptionthrow exend Try '--------------------- Writes the connection string to the Web.config-----------------------------------Trydim FileInfo as System.IO.FileInfo = New System.IO.FileInfo ( Me.Context.Parameters.Item ("Targetdir") & "\web.config") if not fileinfo.exists thenthrow New installexception (" Config file "") End If ' materialized Xml document Dim XmlDocument As New System.Xml.XmlDocumentxmldocument.load (fileinfo.fullname) ' Find nodes in appsettings Dim node as System.Xml.XmlNodedim foundit as Boolean = falsefor each node in Xmldocument.item ("Configura tion "). Item ("AppSettings") If Node.name = "Add" thenif Node.Attributes.GetNamedItem ("key"). Value = "ConnString" Then "Write connection string Node.attributes.getnameditem (" value "). Value = String.Format (" Persist security info=false;data source={0};initial Catalog={1}; User id={2}; PASSWORD={3}; Packet size=4096; Pooling=true; Max Pool size=100; Min Pool size=1 ", _me.context.parameters.item (" Server "), Me.Context.Parameters.Item (" dbname "), Me.Context.Parameters.Item ("User"), Me.Context.Parameters.Item ("pwd")) Foundit = TrueEnd IfEnd IfNext nodeif not Foundit thenthrow New installexception ("web. Config file does not contain the ConnString connection string setting ") End Ifxmldocument.save (fileinfo.fullname) Catch ex as Exceptionthrow exend Tryend SubEnd Class
A bit difficult is the process class, which calls the Osql.exe program to execute the SQL statement osql-u,-p,,-d,-i.
Web.config's modified code is implemented using the syntax of XML. It's not hard to understand.
Finally compile the build! As shown in figure:
Installation interface: as shown in
Haha, finally finished writing, also do not know whether to write well.
Finally, thank Lee Honggen and Microsoft's lecturer. Combined with their common experience, deployment is really simple.