Net installation and deployment project

Source: Internet
Author: User
Source: http://blog.csdn.net/lovezhouliA/article/details/2643375
1). Create a deployment project
1. Point to "add project" on the "file" menu and select "new project ". 2. In the "Add new project" dialog box, select "Install and deploy Project" in the "project type" pane, and select "Install Project" in the "template" pane ". In the Name box, type setup1. 3. Click OK to close the dialog box. 4. The project is added to Solution Explorer and opened in the file system editor. 5. In the "properties" window, select ProductName properties and type the information management system. 2). Add the output of the main program project to the deployment project.1. In the file system Editor, select Application folder ". On the "operations" menu, point to "add" and select "project output ". 2. In the "add project output group" dialog box, select "your program" from the "project" drop-down list ". 3. Click OK to close the dialog box. 4. Select the "main output" and "Content File" groups from the list, and click "OK ". 3). Create the installer class1. Point to "new" on the "file" menu and select "project ". 2. In the "new project" dialog box, select "Visual Basic Project" in the "project type" pane and select "class library" in the "template" pane ". In the "name" box, type installDB. 3. Click Open to close the dialog box. 4. Select "Add new project" from the "project" menu ". 5. In the "Add new project" dialog box, select "Installer class ". In the "name" box, type installDB. 6. Click OK to close the dialog box. 7. The detailed code is attached. 4). Create a custom installation dialog box1. Select the "setup1" project in Solution Explorer. On the "View" menu, point to "Editor" and select "User Interface ". 2. In the User Interface Editor, select the "Start" node under "installation. On the "operations" menu, select "add dialog box ". 3. In the "add dialog box", select the "License Agreement" dialog box and click "OK" to close the dialog box. 4. In the Add dialog box, select the text box (A) and click OK to close the dialog box. 5. On the "operations" menu, select "Move Up ". Repeat this step until the "text box (A)" dialog box is located on the "Install Folder" node. 6. in the "properties" window, select the BannerText attribute and type: Install database. 7. select the BodyText attribute and type: the installer will install the database on the target machine 8. select the Edit1Label attribute and type: Database Name: 9. select the Edit1Property attribute and type CUSTOMTEXTA110. select the Edit1Value attribute and type dbservers11. select the Edit2Label attribute and enter: Server Name: 12. select the Edit2Property attribute and type CUSTOMTEXTA213. select the Edit2Value attribute and type: (local) 14. select the Edit3Label attribute and type: Username: 15. select the Edit3Value attribute and type: sa16. select the Edit3Property attribute and type CUSTOMTEXTA317. select the Edit4Label attribute and enter: Password: 18. select the Edit4Property property and type CUSTOMTEXTA419. select the Edit2Visible, Edit3Visible, and Edit4Visible attributes, and set them to true. 5). Create a custom operation1. Select the "setup1" project in Solution Explorer. On the "View" menu, point to "Editor" and select "Custom operations ". 2. Select the "Install" node in the Custom operation editor. On the "operations" menu, select "add custom operation ". 3. In the "select project items" dialog box, double-click "application folder ". 4. Select "primary output from installDB (activity)" and click "OK" to close the dialog box. 5. in the "properties" window, select the CustomActionData attribute and type "/dbname = [CUSTOMTEXTA1]/server = [CUSTOMTEXTA2]/user = [CUSTOMTEXTA3]/pwd = [CUSTOMTEXTA4]/targetdir =" [TARGETDIR]/"". Appendix:/targetdir = "[TARGETDIR]/" is the target path after installation. To obtain the path after installation in the installDB class, we set this parameter. 6). Add files1. back up SQL Server to a file DB. add dat to the "setup1" project (right-click the database in the Enterprise Manager> all jobs> back up the database and back up it into a file named DB. dat) 2. set the Installation File LisenceFile. add rtf to "setup1" Project 3. in the User Interface Editor, select the license agreement and set the LisenceFile attribute to LisenceFile. rtf file 4. generally, dependencies are automatically added to "detected dependencies". If not, manually add them to Step 5)
Crystal_Managed2003.msm (if there is a crystal Report)
Dotnetfxredist_x86.msm (. net must be required)
... (If any other dll is referenced)
5. if a crystal report is used, manually add the file to be included: Project --> Add --> Merge Module (add your program file) (including dotNetFramework and MDAC27) at: C: /Program Files/Common Files/Merge Modules/. * The specific functions are as follows:
(Managed component MSM processes distribution of all managed components, including Windows form viewer, Web form viewer, and all Crystal Decisions namespaces)
* Crystal_Managed2003.msm
Crystal_Managed2003_chs.msm (for all other files required for running the report, the database accesses the MSM to process its distribution. These include database, export, and chart drivers .)
* Crystal_Database_access2003.msm
Crystal_Database_access2003_chs.msm (KeyCode MSM processes Crystal Decisions key number installation. Note that the merging module is added; otherwise, the "MergeMouduleProperties" attribute is not available)
* Crystal_regwiz2003.msm (if the report file uses the dataset object of ADO. NET, VC_User_CRT71_RTL_X86 _ ---. msm and VC_User_STL71_RTL_X86 _ ---. the msm module must also be included in the installation project. In addition, the "Module Retargetable Folder" item of the File Installation attribute of the two modules must be changed to the system directory)
VC_User_CRT71_RTL_X86 _ ---. msm
VC_User_STL71_RTL_X86 _ ---. msm
(Many people often encounter query errors. Add this to them) 6. open solution --> right-click the attribute of Crystal_regwiz2003.msm, and fill in the "License Key" in "MergeMouduleProperties": aap5gks1_gde100ds (this is the registration code used to generate the Crystal Report !)

7). added the uninstall function during packaging:Method 1:
1. Upload the msiexec.exe file in the package object (generally found in c:/windows/system32)
2. Upload the program file in the file system, press "right" on "msiexec.exe", select "Uninstall" to create a shortcut, and rename the shortcut to "Uninstall ".
3. Change the Arguments of this shortcut to "/x {product id}", and the value of product id is the ProductCode encoding value of the packaging destination. Method 2: (recommended)
1. Complete the installation package, and write down the ProductCode (select the solution Resource Manager root directory such as setup1, and then view the property tag, not the right-click attribute ).
2.use vs.netto create a new console program uninst.exe File
'Power by: landlordh
'For 2000, xp, 2003
Module uninstall
Sub Main ()
Dim myProcess As Process = New Process
If System. Environment. OSVersion. ToString. IndexOf ("NT 5") Then
MyProcess. Start ("msiexec", "/X {2B65D4A9-C146-4808-AB4B-321FB0779559}") "changed to your own ProductCode
End If
MyProcess. Close ()
End Sub
End Module
3.add the exefiles in the binlog of the console program to the package program file, and create the uninst.exe shortcut in the program group.
 
8). Add the. net environment and MDAC features during packaging:
After the PluginInstaller. msi plug-in of MS is installed, it is automatically packaged with the package tool of vb.net.
In the. net framework environment, and then set up the following steps, you can also package MDAC. Use the Setup project to install MDAC
1. Make sure that the Visual Studio. NET Framework Bootstrap plug-in is installed.
2. Select the Setup project in Solution Explorer.
From the View menu, point to the Editor and select Launch Conditions ).
3. Select the Requirements on Target Machine node.
From the Action menu, select Add Registry Launch Condition (Add Registry search ).
4. Select Search for RegistryEntry1. In the Properties window,
Select the RegKey attribute and type Software/Microsoft/DataAccess.
5. Select the Root attribute and vsdrrHKLM.
6. Select the Value Attribute and type FullInstallVer.
7. Select the Property and type MDACSEARCH.
8. In Launch Conditions Editor (startup condition), add the Condition1 node.
Select the Condition1 node, select the Condition attribute in the Properties window, and select MDACSEARCH> = "2.6 ".
9. Select the Setup project in Solution Explorer. On the Project menu, select Properties.
10. Set the Bootstrapper attribute to Windows Installer Bootstrapper (Windows Installer ). Appendix:

Installdb. vb class, to add reference system. configuration. install. dll:

Imports System. ComponentModel
Imports System. Configuration. Install

<RunInstaller (True)> Public Class Installer1
Inherits System. Configuration. Install. Installer

# Region "code generated by the component designer"

Public sub new ()
Mybase. New ()

'The call is required by the component designer.
Initializecomponent ()

'Add any initialization after initializecomponent () is called.

End sub

'Installer override dispose to clear the component list.
Protected overloads overrides sub dispose (byval disposing as Boolean)
If disposing then
If not (components is nothing) then
Components. Dispose ()
End if
End if
Mybase. Dispose (disposing)
End sub

'Required by the component designer
Private components as system. componentmodel. icontainer

'Note: The following process is required by the component designer
'You can use the component designer to modify this process.
'Do not use the code editor to modify it.
<System. Diagnostics. debuggerstepthrough ()> private sub initializecomponent ()
Components = new system. componentmodel. Container
End sub

# End Region

Public overrides sub install (byval statesaver as system. Collections. idictionary)
MyBase. Install (stateSaver)
If Not InstallDB () Then
'Installation failed.
Me. Uninstall (stateSaver)
Exit Sub
End If
DeleteFile (String. Format ("{0} DB. dat", Me. Context. Parameters. Item ("targetdir ")))
End Sub

Public Overrides Sub Uninstall (ByVal stateSaver As System. Collections. IDictionary)
'Perform reverse installation
MyBase. Uninstall (stateSaver)
DeleteFile (String. Format ("{0} DB. dat", Me. Context. Parameters. Item ("targetdir ")))
End Sub

Private Sub DeleteFile (ByVal paths As String)
'Delete the specified file
Try
Dim delFile As New System. IO. FileInfo (paths)
If delFile. Exists Then
DelFile. Delete ()
End If
Catch ex As Exception
End Try
End sub

Private sub createsql (byval paths as string)
Dim file as system. Io. streamwriter
Dim dB as string = string. Format ("{0}", me. Context. Parameters. Item ("dbname "))
Dim path as string = string. Format ("{0}", me. Context. Parameters. Item ("targetdir "))
Try
Dim s as new system. Text. stringbuilder
S. append ("use master" & vbcrlf)
S. append ("" & vbcrlf)
S. Append ("if not exists (select * from sysdatabases where name = '" & db & "')" & vbCrLf)
S. Append ("BEGIN" & vbCrLf)
S. Append ("create database" & db & vbCrLf)
S. Append ("END" & vbCrLf)
S. Append ("" & vbCrLf)
S. Append ("if exists (select * from sysdevices where name = 'dbdisk')" & vbCrLf)
S. Append ("BEGIN" & vbCrLf)
S. Append ("EXEC sp_dropdevice 'dbdisk'" & vbCrLf)
S. Append ("END" & vbCrLf)
S. Append ("Else" & vbCrLf)
S. Append ("BEGIN" & vbCrLf)
S. Append ("EXEC sp_addumpdevice 'disk', 'dbdisk', '" & path & "DB. dat'" & vbCrLf)
S. Append ("END" & vbCrLf)
S. Append ("" & vbCrLf)
S. Append ("restore database" & db & vbCrLf)
S. Append ("from disk = '" & path & "DB. dat'" & vbCrLf)
S. Append ("with replace ")
File = New System. IO. StreamWriter (paths)
File. Write (s. ToString)
Catch ex As Exception
Finally
File. Close ()
End Try
End Sub

Private Function InstallDB () As Boolean
'Install the database and call automatic batch processing.
Try
'Create a temporary script
CreateSql (String. Format ("{0} Mydb2000tp. SQL", Me. Context. Parameters. Item ("targetdir ")))
'Call osql to execute the script
Dim sqlProcess As New System. Diagnostics. Process
SqlProcess. StartInfo. FileName = "osql.exe"
SqlProcess. startInfo. arguments = String. format ("-U {0}-P {1}-S {2}-I {3} Mydb2000tp. SQL ", Me. context. parameters. item ("user"), Me. context. parameters. item ("pwd"), Me. context. parameters. item ("server"), Me. context. parameters. item ("targetdir "))
SqlProcess. StartInfo. WindowStyle = ProcessWindowStyle. Hidden
SqlProcess. Start ()
SqlProcess. WaitForExit () 'waiting for execution
SqlProcess. Close ()
'Delete the script file
DeleteFile (String. Format ("{0} Mydb2000tp. SQL", Me. Context. Parameters. Item ("targetdir ")))
Return True
Catch ex As Exception
Return False
End Try
End Function

End Class

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.