ASP. NET installation and deployment code implementation

Source: Internet
Author: User

Introduction to ASP. NET installation and deployment code implementation:

1. Add the script file db. SQL generated by SQL Server to the "Test Installer" project.

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 attribute to the LisenceFile. rtf file.

The following ASP. NET installation and deployment code implementation is the most important part of the entire deployment.

Add the code to the installer class, dbcustomaction. vb class

 
 
  1. Imports System. ComponentModel
  2.  
  3. Imports System. Configuration. Install
  4.  
  5. Imports System. IO
  6.  
  7. Imports System. Reflection
  8.  
  9. <Runinstaller (True)> Public Class DBCustomActionClass DBCustomAction
  10.  
  11. Inherits System. Configuration. Install. Installer 
  12.  
  13.  
  14. # Region "code generated by the component designer" 
  15.  
  16. PublicSub New ()
  17.  
  18. Mybase.New()
  19.  
  20. 'The call is required by the component designer
  21.  
  22. Initializecomponent ()
  23.  
  24. 'Add any initialization after InitializeComponent () is called.
  25.  
  26. End Sub
  27.  
  28. 'Installer override dispose to clear the component list.
  29.  
  30. ProtectedOverloads Overrides Sub Dispose () Sub Dispose (ByVal disposing As Boolean)
  31.  
  32. IfDisposing Then
  33.  
  34. IfNot (components Is Nothing) Then
  35.  
  36. Components. dispose ()
  37.  
  38. End If
  39.  
  40. End If
  41.  
  42. Mybase. dispose (disposing)
  43.  
  44. End Sub
  45.  
  46. PrivateComponents As System. ComponentModel. IContainer
  47.  
  48. <System. diagnostics. debuggerstepthrough ()>
  49. Private Sub InitializeComponent ()
  50.  
  51. End Sub 
  52.  
  53. # End Region 
  54.  
  55. 'Execute SQL statements
  56.  
  57. PrivateSub ExecuteSql () Sub ExecuteSql (ByVal conn As String,
  58. ByVal DatabaseName As String, ByVal SQL As String)
  59.  
  60. Dim mySqlConnection As New SqlClient. SqlConnection (conn)
  61.  
  62. Dim Command As New SqlClient. SqlCommand (SQL, mySqlConnection)
  63.  
  64. Command. connection. open ()
  65.  
  66. Command. connection. changedatabase (databasename)
  67.  
  68. Try 
  69.  
  70. Command.exe cutenonquery ()
  71.  
  72. Finally 
  73.  
  74. 'Close Connection
  75.  
  76. Command. connection. close ()
  77.  
  78. End Try
  79.  
  80. End Sub
  81.  
  82. PublicOverrides Sub Install () Sub Install (ByVal stateSaver
  83. As System. Collections. IDictionary)
  84. MyBase. Install (stateSaver)
  85.  
  86. '---------- ASP. NET installation and deployment code to build a database ------------
  87.  
  88. Try 
  89.  
  90. Dim connStr As String = String. Format ("data source = {0 };
  91. User id = {1}; password = {2 };
  92. Persist security info =False; Packet size = 4096 ",
  93. Me. Context. Parameters. Item ("Server"),
  94. Me. Context. Parameters. Item ("User"),
  95. Me. Context. Parameters. Item ("Pwd"))
  96.  
  97. 'Create a database based on the input database name
  98.  
  99. Executesql (connstr,"Master",
  100. "Create database"+ Me. Context. Parameters. Item ("Dbname"))
  101.  
  102. 'Asp. NET installation and deployment code implementation: Calling osql execution scripts
  103.  
  104. Dim sqlProcess As New System. Diagnostics. Process
  105.  
  106. Sqlprocess. startinfo. filename ="Osql.exe" 
  107.  
  108. Sqlprocess. startinfo. arguments = String. Format ("-U {0}-P {1}-d {2}-I {3} db. SQL",
  109. Me. Context. Parameters. Item ("User"), Me. Context. Parameters. Item ("Pwd"),
  110. Me. Context. Parameters. Item ("Dbname"), Me. Context. Parameters. Item ("Targetdir"))
  111.  
  112. Sqlprocess. startinfo. windowstyle = ProcessWindowStyle. Hidden
  113.  
  114. Sqlprocess. start ()
  115.  
  116. Sqlprocess. waitforexit () 'waiting for execution
  117.  
  118. Sqlprocess. close ()
  119.  
  120. 'Asp. NET installation and deployment code implementation: deleting script files
  121.  
  122. Dim sqlFileInfo As New System. IO. FileInfo (String. Format ("{0} db. SQL",
  123. Me. Context. Parameters. Item ("Targetdir")))
  124.  
  125. IfSqlFileInfo. Exists Then
  126.  
  127. Sqlfileinfo. delete ()
  128.  
  129. End If
  130.  
  131. CatchEx As Exception
  132.  
  133. ThrowEx
  134.  
  135. End Try
  136.  
  137.  
  138.  
  139. '-ASP. NET installation and deployment code implementation: writing the connection string to Web. config --
  140.  
  141. Try 
  142.  
  143. Dim FileInfo As System. IO. FileInfo = New System. IO.
  144. FileInfo (Me. Context. Parameters. Item ("Targetdir")&"\ Web. config")
  145.  
  146. IfNot FileInfo. Exists Then
  147.  
  148. ThrowNew InstallException ("No configuration file found")
  149.  
  150. End If
  151.  
  152. 'Instantiate xml document
  153.  
  154. Dim XmlDocument As New System. Xml. XmlDocument
  155.  
  156. Xmldocument. load (fileinfo. fullname)
  157.  
  158. 'Find the node in the deleetask'
  159.  
  160. Dim Node As System. Xml. XmlNode
  161.  
  162. Dim FoundIt As Boolean = False
  163.  
  164. ForEach Node In XmlDocument. Item ("Configuration"). Item ("AppSettings")
  165.  
  166. IfNode. Name ="Add"Then
  167.  
  168. IfNode. Attributes. GetNamedItem ("Key"). Value ="ConnString"Then
  169.  
  170. 'Asp. NET installation and deployment code implementation-writing connection string
  171.  
  172. Node. attributes. getnameditem ("Value"). Value = String.
  173. Format ("Persist Security Info = False; Data Source = {0 };
  174. Initial Catalog = {1}; User ID = {2}; Password = {3 };
  175. Packet Size = 4096; Pooling =True; Max Pool Size = 100;
  176. Min Pool Size = 1 ",_
  177.  
  178. Me. context. parameters. item ("Server"),
  179. Me. Context. Parameters. Item ("Dbname"),
  180. Me. Context. Parameters. Item ("User"),
  181. Me. Context. Parameters. Item ("Pwd"))
  182.  
  183. Foundit = True
  184.  
  185. End If
  186.  
  187. End If
  188.  
  189. Next Node
  190.  
  191. IfNot FoundIt Then
  192.  
  193. ThrowNew InstallException ("The web. Config file does not contain the connString connection string Settings")
  194.  
  195. End If
  196.  
  197. Xmldocument. save (fileinfo. fullname)
  198.  
  199. CatchEx As Exception
  200.  
  201. ThrowEx
  202.  
  203. End Try
  204.  
  205. End Sub
  206.  
  207. End Class

The processclass, which is somewhat difficult, calls the osql.exe program to execute the SQL statements osql-U,-P,-d,-I.

The modification code of web. config is implemented using xml syntax. Not difficult to understand.

Finally compiled and generated!

 

Installation interface:

This section describes the implementation of ASP. NET installation and deployment code. It is helpful for you to learn how to install and deploy ASP. NET.

  1. Detailed illustration of creating a project for ASP. NET installation and deployment
  2. Import project diagram of ASP. NET installation and deployment
  3. Create dialog box for ASP. NET installation and deployment
  4. Create custom operations for ASP. NET installation and deployment
  5. ASP. NET installation and deployment: Creating and installing programs

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.