DOTNET System Setup Production STEPBYSTEP (including Framework Installation and Database Installation) C #

xiaoxiao2021-04-10  479

A few days ago, I have been arranged by the boss, and I haven't done it, I want to use what tool to make installation packages. Now there are many tools (Wise, etc.), downloaded a try, I feel that research is too trouble, I want to use the installation package made by .NET installer. However, it is really encountered in the production process.

Reference: Li Honggen's "NET platform deployment (installation database and automatic configuration)" Personally use C #, translate his VB code, huh, huh.

First, you need to export the database table structure you want to build. Use the SlQServer's Export Wizard to the watch structure, save it to the db.sql file.

Optional step: Install the Framework boot program plugin. Installing this plug-in installed package You can use the Microsoft Visual Studio .Net 2003 boot the program plugin, you can easily create the installer, re-distribute the .NET Framework 1.1 with your application. Booter plugin PluginInstaller.msi under address: http://www.microsoft.com/downloads/details.aspx?familyid=627921a0-d9e7-43d6-a293-72f9c370bd19&displayLANG=zh-CN

Step 1: Create a deployment item 1. Point "Add Project" on the File menu and select New Project. 2. In the Add New Project dialog box, select Install and Deploy Projects in the Project Type pane, then select "Install Project" in the Template pane. Type Setup 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.

Step 2: Create an installer class 1. Point "New" on the File menu and select Project. 2. In the New Project dialog box, select Projects 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. (After the code attached)

Step 3: Add the output of the project to the deployment project 1. In the File System Editor, select the Application folder. On the "Operation" menu, point to Add, then select "Project Output". 2. In the Add Project Output Group dialog, select the Project drop-down list in your project. 3. Click "OK" to close the dialog. 4. Select "Main Output" from the list, and then click OK.

Step 4: Create a custom installation dialog 1. Select the "SETUP" item 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 Edit4Label attribute and type: SA user password:. 18. Select the Edit4Property property and type CustomTexta4. Step 5: Create custom operations 1. Select the "Setup" item 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")

Step 6: Add DB.SQL and other files you need to the project, and then package it. There is also the most important question. At that time, I had more than three hours, just using the .NET program package, the installation process user selects a space in the installation path selected. why? It turned out that when SQL Server's OSQL execution command line mode, if your installation path contains space, the command line cannot be executed correctly. "OSQL -U Userid -p Password -D DBName -i C: /Test/db.sql" can also directly modify the installed app.config to complete your configuration, and Li Honggen has a related introduction.

DBCustomAction.cs

Using system; using system.collections; using system.ComponentModel; use system.configuration.install;

A summary description of the Namespace dbcustomaction {///

/// dbcustomaction. /// [RunInstaller (TRUE)] public class dbcustomaction: system.configuration.install.installer {/// // The required designer variable. /// private system.componentmodel.container components = null;

Public dbcustomAction () {// This call is required for the designer. InitializationComponent ();

// Todo: Add any initialization after INITIALIZEC Mobomponent call

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose

#REGION component designer generated code ///

/// designer supports the required method - Do not use the code editor to modify the // / this method. /// private vid initializecomponent () {components = new system.componentmodel.container ();} #ENDREGION

private void ExecuteSql (string connStr, string DatabaseName, string Sql) {SqlConnection conn = new SqlConnection (connStr); SqlCommand cmd = new SqlCommand (Sql, conn); conn.Open (); conn.ChangeDatabase (DatabaseName); try {cmd .Executenonquery (); finally {conn.close ();

Public override void install (system.collections.idictionary statesaver) {base.install (statesaver); try {// ---------------------- Create Database ---------------------------- String Connstr = String.Format ("Data Source = {0}; user ID = {1}; Password = {2}; Persist security info = false; packet size = 4096, this.context.parameters ["server"], this.context.Parameters ["User"], this.context.Parameters ["PWD"] ); ExecuteSql (connStr, "master", "CREATE DATABASE" this.Context.Parameters [ "dbname"]); System.Diagnostics.Process sqlProcess = new System.Diagnostics.Process (); sqlProcess.StartInfo.FileName = " Osql.exe "; sqlprocess.startinfo.arguments = string.format (" -u {0} -p {1} -d {2} -i {3} db.sql ", this.Context.Parameters [" user " ], this.Context.Parameters [ "pwd"], this.Context.Parameters [ "dbname"], this.Context.Parameters [ "targetdir"]); sqlProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; SqlProcess.Start (); sqlprocess.waitForeXit (); // Wait for execution} catch (Exceptio N e) {console.write (e.tostring ());} finally {}}}}

转载请注明原文地址:https://www.9cbs.com/read-133287.html

New Post(0)