自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

ASP.NET安裝部署代碼實(shí)現(xiàn)

開發(fā) 后端
ASP.NET安裝部署代碼實(shí)現(xiàn)是如何的呢?那本文就向你介紹這方面的內(nèi)容。

ASP.NET安裝部署代碼實(shí)現(xiàn)之添加文件簡介:

1. 將SQL Server生成的腳本文件db.sql添加到“Test Installer”項目

2. 將安裝文件LisenceFile.rtf添加到“Test Installer”項目

3. 在用戶界面編輯器中,選擇許可協(xié)議,設(shè)置LisenceFile屬性為LisenceFile.rtf文件

以下的ASP.NET安裝部署代碼實(shí)現(xiàn)是整個部署的最重要的一部分了

將代碼添加到安裝程序類中,dbcustomaction.vb類

  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 "組件設(shè)計器生成的代碼 "  
  15.  
  16. public Sub New()Sub New()  
  17.  
  18. mybase.new()  
  19.  
  20. '該調(diào)用是組件設(shè)計器所必需的  
  21.  
  22. initializecomponent()  
  23.  
  24. '在 InitializeComponent() 調(diào)用之后添加任何初始化  
  25.  
  26. end Sub  
  27.  
  28. ' Installer 重寫 dispose 以清理組件列表。  
  29.  
  30. protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)  
  31.  
  32. if disposing Then  
  33.  
  34. if Not (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. private components As System.ComponentModel.IContainer  
  47.  
  48. ﹤system.diagnostics.debuggerstepthrough()﹥   
  49. Private Sub InitializeComponent()Sub InitializeComponent()  
  50.  
  51. end Sub  
  52.  
  53. #end Region  
  54.  
  55. '執(zhí)行sql 語句  
  56.  
  57. private Sub 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.executenonquery()  
  71.  
  72. finally 
  73.  
  74. 'close Connection  
  75.  
  76. command.connection.close()  
  77.  
  78. end Try  
  79.  
  80. end Sub  
  81.  
  82. public Overrides Sub Install()Sub Install(ByVal stateSaver   
  83. As System.Collections.IDictionary)  
  84. MyBase.Install(stateSaver)  
  85.  
  86. ' ----------ASP.NET安裝部署代碼實(shí)現(xiàn)建立數(shù)據(jù)庫------------  
  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. '根據(jù)輸入的數(shù)據(jù)庫名稱建立數(shù)據(jù)庫  
  98.  
  99. executesql(connstr, "master",   
  100. "CREATE DATABASE " + Me.Context.Parameters.Item("dbname"))  
  101.  
  102. 'ASP.NET安裝部署代碼實(shí)現(xiàn)之調(diào)用osql執(zhí)行腳本  
  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() '等待執(zhí)行  
  117.  
  118. sqlprocess.close()  
  119.  
  120. 'ASP.NET安裝部署代碼實(shí)現(xiàn)之刪除腳本文件  
  121.  
  122. dim sqlFileInfo As New System.IO.FileInfo(String.Format("{0}db.sql",   
  123. Me.Context.Parameters.Item("targetdir")))  
  124.  
  125. if sqlFileInfo.Exists Then  
  126.  
  127. sqlfileinfo.delete()  
  128.  
  129. end If  
  130.  
  131. catch ex As Exception  
  132.  
  133. throw ex  
  134.  
  135. end Try  
  136.  
  137.  
  138.  
  139. ' -ASP.NET安裝部署代碼實(shí)現(xiàn)之將連接字符串寫入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. if Not FileInfo.Exists Then  
  147.  
  148. throw New InstallException("沒有找到配置文件")  
  149.  
  150. end If  
  151.  
  152. '實(shí)例化xml文檔  
  153.  
  154. dim XmlDocument As New System.Xml.XmlDocument  
  155.  
  156. xmldocument.load(fileinfo.fullname)  
  157.  
  158. '查找到appsettings中的節(jié)點(diǎn)  
  159.  
  160. dim Node As System.Xml.XmlNode  
  161.  
  162. dim FoundIt As Boolean = False  
  163.  
  164. for Each Node In XmlDocument.Item("configuration").Item("appSettings")  
  165.  
  166. if Node.Name = "add" Then  
  167.  
  168. if Node.Attributes.GetNamedItem("key").Value = "connString" Then  
  169.  
  170. 'ASP.NET安裝部署代碼實(shí)現(xiàn)之寫入連接字符串  
  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. if Not FoundIt Then  
  192.  
  193. throw New InstallException("web.Config 文件沒有包含connString連接字符串設(shè)置")  
  194.  
  195. end If  
  196.  
  197. xmldocument.save(fileinfo.fullname)  
  198.  
  199. catch ex As Exception  
  200.  
  201. throw ex  
  202.  
  203. end Try  
  204.  
  205. end Sub  
  206.  
  207. end Class 

有點(diǎn)難度的就是那個Process類,它調(diào)用了osql.exe程序,來執(zhí)行sql語句osql -U,-P,,-d,-i。

web.config的修改代碼是利用xml的語法實(shí)現(xiàn)。不是很難理解。

***編譯生成!如圖:

編譯生成圖 

安裝界面:如圖

安裝界面圖

ASP.NET安裝部署代碼實(shí)現(xiàn)的基本情況就向你介紹到這里,希望對你學(xué)習(xí)ASP.NET安裝部署有所幫助。

【編輯推薦】

  1. ASP.NET安裝部署之創(chuàng)建項目詳細(xì)圖解
  2. ASP.NET安裝部署之導(dǎo)入項目圖解
  3. ASP.NET安裝部署之創(chuàng)建對話框圖解
  4. ASP.NET安裝部署之創(chuàng)建自定義操作
  5. ASP.NET安裝部署之創(chuàng)建安裝程序類
責(zé)任編輯:仲衡 來源: 博客園
相關(guān)推薦

2009-07-29 16:31:39

ASP.NET安裝部署

2009-08-05 16:59:55

ASP.NET組件設(shè)計

2009-08-10 16:37:26

ASP.NET安裝部署

2009-07-23 13:19:51

2009-07-23 13:09:23

2009-08-10 17:04:42

ASP.NET安裝部署

2009-08-10 16:14:26

ASP.NET安裝部署

2009-08-04 17:16:16

ASP.NET代碼優(yōu)化

2009-08-10 18:19:37

ASP.NET安裝環(huán)境

2009-08-10 18:43:05

ASP.NET安裝步驟

2009-08-05 10:16:54

部署ASP.NET應(yīng)用

2009-07-22 17:45:35

ASP.NET教程

2009-08-03 14:22:33

什么是ASP.NET

2009-07-28 17:17:19

ASP.NET概述

2009-08-12 14:10:37

asp.net分頁代碼

2009-08-10 16:50:34

ASP.NET安裝部署

2009-08-10 16:58:45

ASP.NET安裝部署

2009-08-04 11:29:14

HTML代碼ASP.NET控件

2009-07-23 10:08:24

asp.net mvc

2009-07-28 09:45:34

Webpart部署方式使用ASP.NET
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號