Deploying a Web solution is more convenient under the .NET platform. We can use Visual Studio.net 2003 to add a web installation project, add the primary output and content files of the project in the deployed File System Editor, which is very simple to complete the production of the installer. However, the installer that is made is just the DLL file compiled by the web page and the ASP.NET program to the IIS directory of the target machine. For a general application, you can use the Access database, you can pack it into the installer together. If the database is SQL Server, you need to install the database when deploying, the installation program will be complex, and we need to customize the installer class. The SQL script is executed in the installer class and the connection string is written to Web.config. l Installing the Database Microsoft MSDN describes the establishment of a database when deploying an application. Such as:
Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxwlkwalkthroughusingcustomActionTOCREATEDATABASEDURINSTALLATION.ASP
This method is to create an installer class, call ADO.NET in the installer class to perform SQL statements (SQL statements in a text file) to create a database. However, this approach has a problem. If you generate all the schedule, view, stored procedures with SQL Server2000, use ADO.NET to execute this script file, will have many "Go" statements in the script. An error occurred. Of course, we can replace "Go" into a newline, and use the ADO.NET article to execute the SQL statement. Obviously, such efficiency is relatively low. The best way is to call OSQL execution scripts. (Or create a CMD file for a database project, and the CMD file is also called OSQL when the database is established. First, we create a new ASP.NET web application
http:// localhost / vbnettest
And open the VBNetTest project to create a deployment item 1. Point "Add Item" on the File menu and select New Project. 2. In the Add New Project dialog box, select Install and Deploy Projects in the Item Type pane, then select "Web Installation item" in the Template pane. Type Test Installer in the Name box. 3. Click "OK" to close the dialog. 4. The project is added to the Solution Explorer and the file system editor opens. 5. In the Properties window, select the productName property and type GCRM. Add the output of the VBNetTest project to the deployment project 1. In the File System Editor, select the "Web Application" folder. On the "Operation" menu, point to Add, then select "Project Output". 2. In the Add Project Output Group dialog box, select "VBNetTest" in the Project drop-down list. 3. Click "OK" to close the dialog. 4. Select the "Main Output" and "Content File" group from the list, and then click OK. Creating an installer class 1. Point "New" on the File menu and select Project. 2. In the New Project dialog box, select "Visual Basic Project" in the Project Type pane, then select "Class Library" in the Template pane. Type dbcustomAct in the Name box. 3. Click "Open" to close the dialog. 4. Select "Add New Item" from the Project menu. 5. Select "Install Program Class" in the Add New Item dialog. Type dbcustomAct in the Name box. 6. Click OK to close the dialog. Create a custom installation dialog 1. Select the Test Installer project in the Solution Explorer. Point "Editor" on the View menu and select User Interface. 2. In the User Interface Editor, select the "Start" node under "Install". On the Actions menu, select Add Dialog. 3. In the Add Dialog dialog box, select the Law Protocol dialog box, and then click Close the dialog box. 4. In the Add Dialog Box dialog box, select the Text Box (a) dialog box and click "OK" to close the dialog. 5. On the "Operation" menu, select "Top". Repeat this step until the text box (a) dialog is on the "Install Folder" node. 6. In the Properties window, select the bannertext property and type: Install the database .. 7. Select the BodyText property and type: The installer 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 Edit2Label attribute and type: Server Name:. 12. Select the Edit2Property property and type CustomTexta2. 13. Select Edit2Value properties and type: (local). 14. Select the Edit3Label property and type: Username:. 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 Edit4Visible properties and set them to false.
Creating a custom action 1. Select the Test Installer project in the Solution Explorer. Point "Editor" on the View menu and select Customize. 2. Select the "Install" node in the Custom Operation Editor. On the Actions menu, select Add Custom Action. 3. In the "Select Item" dialog box, double-click Application Folder. 4. Select the "Main Output" item from the DBCustomAction, and then click "OK" to close the dialog. 5. In the Properties window, select the CustomActionData property and type / dbname = [CustomTexta1] / Server = [CustomTexta2] / user = [CustomTexta3] / PWD = [CustomTextA4] / Targetdir = "[targetdir] /". Attached / targetdir = "[targetdir] /" is the installed target path, in order to get the installed path in the DBCustomAction class, we set this parameter. In addition, the installed path can also get REFLECTION: DIM ASM as system.reflection.Assembly = _system.Reflection.Assembly.getexecutingassemblyMsgBox ("asm.location") Add file 1. Add SQL Server's script file DB.SQL Add SQL Server To "Test Installer" item 2. Add the installation file Lisncefile.rtf to "Test Installer" item 3. In the User Interface Editor, select the license agreement, set the LisenseFile property to the LisnceFile.rtf file Add the code to the installer class. , DBCustomAction.vb class Imports System.ComponentModelImports System.Configuration.InstallImports System.IOImports System.Reflection
Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean) If disposing ThenIf Not (components Is Nothing) Thencomponents.Dispose () End IfEnd IfMyBase.Dispose (disposing) End SubPrivate components As System.ComponentModel.IContainer
)) SqlProcess.StartInfo.WindowStyle = ProcessWindowStyle.HiddensqlProcess.Start () sqlProcess.WaitForExit () 'awaiting execution sqlProcess.Close ()' delete the script file Dim sqlFileInfo As New System.IO.FileInfo (String.Format ( "{0} DB.SQL ", Me.Context.Parameters.item (" Targetdir "))) ifeqlfileinfo.exists Thensqlfileinfo.delete () end ifcatch exceptionthrow Exend try" -------------------------------------------------------------------------------- ------- Write the connection string to Web.config ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -Trydim fileInfo as system.io.fileinfo = new system.io.fileinfo (Me.Context.Parameters.item ("targetdir") & "Targetdir") & "/web.config")if not fileinfo.exists thenthrow new installexception (" Not found file ") End If 'instantiated XML document Dim XmlDocument As New System.Xml.XmlDocumentXmlDocument.Load (FileInfo.FullName)' found in appSettings node Dim node As System.Xml.XmlNodeDim FoundIt As Boolean = FalseFor Each node in XmlDocument .Item ("configuration"). Item ("appsettings") if node.name = "add" thenif node.attributes.getnamedItem ("key"). Value = "connString" The 'Write connection string node.attributes. GetNamedItem ("Value"). Value = String.Format ("Persi ST 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 connString file does not contain the connection string") End IfXmlDocument.Save (FileInfo.FullName) Catch ex As ExceptionThrow exEnd TryEnd SubEnd Class Finally compile generation!