2018 first release: A [Advanced Installer] package trip, 2018 first release

Source: Internet
Author: User

2018 first release: A [Advanced Installer] package trip, 2018 first release
I. Preface

In the last few days of June 2017, you are all happy for the New Year. The blogger is working overtime to create the. net installation package. Because the first version of the installation package was released years ago, the blogger worked overtime. I originally wanted to use the production tool provided by VS, but anyone who has used it knows that it is really good (tong) to use (ku). All kinds of packages need to be downloaded separately, and the interface is not beautiful, so I decided to discard it. Advanced Installer is recommended for colleagues, but it is not necessary for colleagues to remember the specific usage. Therefore, the bloggers are exploring and moving forward, so they can not help but jump into the trap. In order to avoid later people jump into the same trap, the essay will be noted.

Okay, no nonsense. The text begins!

Ii. Flowchart

As the saying goes, "Do not cut firewood by mistake "!

First of all, we need to clarify what we need to do in each step so that the installation package can be organized and organized in an orderly manner, and it is not easy to make mistakes.

For example, we need to determine whether. net framework3.5 or a later version is installed on the client machine, whether IIS is installed, and whether SQL Server2005 or a later version of the database is installed.

The flowchart of my project is as follows:

Tips1: it is best to draw a flowchart before you start.

3. Start production

With the flowchart, you only need to step by step! There is a lot of information on the Internet about the basic usage of Advanced Installer and the help documentation on the official website. I will not go into details here. To use the custom installation package process, you need to create a dialog box. The blogger uses the enterprise template. The Advanced Installer version is 14.5.2, which is also the latest version.

1. Select a template

First, select Enterprise in the new template, and select the language (Chinese by default). Then, create a project:

Tips2: If the custom dialog box is required in the installation package, select Enterprise.

2. Set Basic Information

The Name is the Name of the installation package, the company is your company, and the version information is very simple.

3. Set the default installation path

Click Package Definition-> Install Parameters and enter the default installation path.

The default content of Application folder is as follows: "[ProgramFilesFolder] [Manufacturer] \ [ProductName]", which indicates the default installation path during installation:

[ProgramFilesFolder] indicates a folder. Here, it is D: \ Program Files (x86 ).

[Manufacturer] indicates the company name. Here it is Landsoft.

[ProductName] indicates the product name. Here it is LandaV9.

 

4. Set installation conditions

Click Requirements-> Launch Conditions-> Software and select the appropriate Conditions. As shown in the flowchart, I should check. Net Framework, IIS, and SQL Server. Note that the condition here refers to the minimum condition. For example, Here SQL Server selects 2005, that is, the client machine should have SQL Server of Version 2005 and later. If not, the system prompts that SQL2005 is not installed.

There are also system conditions, that is, whether the customer's machine is win7 or winxp. If there are more conditions, you can customize them in Custom.

 

5. Add a file or folder

Click Resources-> Files and Folders. Right-click Application Folders and choose Add Folder or Add Files. Five Folders are added for subsequent operations.

6. Custom Dialog box (Dialog)

Before creating a dialog box, you can select a topic and style in Themes.

Click User Interface-> Dialogs, right-click FolderDlg, and select Add Dialog to Add a custom Dialog box for Advanced Installer. select New Dialog to Add an empty Dialog box,

Then we can define the content as follows:

After creating a dialog box, you can drag the appearance of the dialog during installation. This is a small Case for our. Net developers. Let's take a look at the effect:

You can set the default value for the text box:

Tips3: attribute name in the text box. Do not modify it. If there is a major problem with the modification, let's talk about it later!

Because we need to set the connection string, the customer needs to set the database information:

After adding Dialog is selected, select SQLServerConnentionDlg in the pop-up box.

The effect is as follows:

Finally, create a dialog box to deploy the project to IIS:

You can also set the website name and port number: According to the flowchart, the default values here need to be set to Mango and 8001 respectively, and you can modify them on your own.

The new dialog box is displayed.

7. Set required verification

Take the preceding dialog box as an example. Although we have set a default value, the customer accidentally deleted it during the installation process and did not fill it out. In this case, the customer just clicked the next step, problems may occur during installation. Therefore, we need to perform required verification, that is, if there is no value in the text box, the "Next" button is unavailable and a value is available.

Select "Next" and follow the "Control Conditions" below ":

 

Click the New button. In the displayed window, enter "NOT edit_dropping drop or not EDIT_1_DROP_1" in the Condition field and select "Disable" in the Action field.

EDIT_1_DROP and EDIT_1_DROP_1 are the website name and port number. The preceding "NOT" indicates that if either of the two text boxes is NOT filled, the button is unavailable ).

Similarly, add "EDIT_1_DROP AND EDIT_1_DROP_1" AND select Enable in Action. That is, the button is available. In this way, the control is required for verification. Isn't it easy!

 

8. Set Desktop shortcuts

As shown in the flowchart, after the installation is complete, you need to generate a shortcut defense method on the desktop. So next we will do this:

On the Files and Folders tab, right-click Application program cut Folder and select "New program cut". The following page is displayed:

 

In this box, you need to set the naming and parameters of the parameter format to a pass (select the .exe file ). Click OK to display this information in Application export cut Folder.

But don't worry. If this is the case, shortcuts won't work. Because we have not set the executable file corresponding to the shortcut.

Double-click this item. In the displayed dialog box, set export cut Target.

Are you sure you have any questions? In this case, why not set it together when adding shortcuts?

This is because the content in the Shortcut target text box cannot be modified when it is added. This is a pitfall, And the blogger tried it for a long time.

Finally, drag the information to the Desktop. After the installation is complete, the shortcut will be displayed on the Desktop.

4. Set the IIS website name and port number

In the last step of the preceding dialog box, remember the property name of the website name and the port number text box, and then go to the IIS tab:

First, add an application pool named the property name of the website name text box, which is EDIT_1_PROP. In the Advanced Installer, use brackets [] to enclose the property names of the control to indicate the concept of variables.

In Basic Pool Settings, set the Startup Mode of the program Pool to always start. Select the check box, set framework version to 4.0, and managed mode to integration.

Set the application pool in Identity to ApplicationPoolIdentity.

After the application pool is set, set the site again:

Create a new Site with the same Name as EDIT_1_PROP and set the Name and file path in Basic Site Setting.

 

Set the port number in Bindings/SSL, and select all IP addresses not allocated.

 

Select the Application Pool you just created in the Application Pool.

Here, IIS is set.

During the installation process, the Advanced Installer automatically deploys the website. This is really awesome! I have to admire what others do!

5. Set the config file in two ways. 1. directly set it in Advanced Installer.

If an xml file is added, the following message is displayed:

In this case, select the file for configuration modification and click OK, so that you can directly modify the file in Advanced Installer.

Find the node to be modified and replace it with the attributes of the text box:

In this way, the corresponding node in the config file will be replaced with the value entered by the customer during the installation process.

Do you still remember Tips3? We have said that if the attribute name of the text box is modified, after this setting, the value in config will not be set to the value entered by the customer and will always be the default value set in the text box.

Remember !!! Three exclamation points for important things!

2. Use a custom dll file

For more information, see section 6.

Vi. Custom dll

Click Custome Behavior-> Custom Actions and select. Net Installer Class action. In this case, you will be asked to select the dll file in the file.

Before that, open your Visual Studio and create a new class library project named InstallLandaV9ServiceT. then create an installer class and override the Install method.

Here, let's pause and ask ourselves: how can we receive parameters passed from Advanced Installer in a program?

If we have added this dll to the Advanced Installer, you can add parameters to the Installer Class Paramters.

For example, to upload the file path to the background, you can add: Name Is FilePath and Value is [APPDIR] \.

Note that when passing the file path, the Value is [APPDIR] \. Do not miss this.

Tips4: When transferring the file path, the Value is [APPDIR] \. Please do not miss this.

The Value of other parameters must be set to the attribute name of the corresponding text box in the format of [attribute name].

Let's take a look at the Code:

public override void Install(IDictionary stateSaver){    Parameters configParms = new Parameters();    configParms.FilePath = Context.Parameters["FilePath"];    configParms.ServerPath = Context.Parameters["ServerPath"];    configParms.ClientPath = Context.Parameters["ClientPath"];    configParms.DataSource = Context.Parameters["DataSource"];    configParms.UserId = Context.Parameters["UserId"];    configParms.Password = Context.Parameters["Password"];    new Operators().UpdateLandaV9Config(configParms);    base.Install(stateSaver);}

Here, we mainly receive parameters from the Advanced Installer, and then update the configuration file in the Operators class.

Do you still remember Tips3? If the attribute name is modified there, the parameters received here are also the default values of the text box.

There are three main tasks: getting the connection string, updating the connection string, and installing the service.

public void UpdateLandaV9Config(Parameters configParms){    string filePath = Path.Combine(configParms.FilePath, "LandaV9Service", "LandaEntryInfoService.exe.config");    string connectionString = this.GetConnectionString(configParms);    this.UpdateConnections(filePath, connectionString);this.InstallService(Path.Combine(configParms.FilePath, "LandaV9Service"));}

Do you still remember Tips4? If you only write [APPDIR] instead of [APPDIR] \ when passing the file path, the "FileNotFound" exception will be thrown when the program runs here!

Let's take a look at the specific code:

/// <Summary> /// obtain the connection string /// </summary> /// <param name = "op"> </param> /// <returns> </returns> public string GetConnectionString (Parameters op) {return string. format ("Data Source = {0}; Initial Catalog = LandaEntryManager; Persist Security Info = True; User ID = {1}; Password = {2}", op. dataSource, op. userId, op. password );} /// <summary> /// update the connection string /// </summary> /// <param name = "filePath"> </param> /// <param name = "conn" > </Param> public void UpdateConnections (string filePath, string conn) {XmlDocument xmlDocument = new XmlDocument (); xmlDocument. load (filePath); XmlElement xmlElement = (XmlElement) xmlDocument. selectSingleNode ("/configuration/connectionStrings/add [@ name = 'landaentrymanager']"); if (xmlElement! = Null) xmlElement. SetAttribute ("connectionString", conn); xmlDocument. Save (filePath );}

Let's take a look at the installation service:

/// <Summary> /// install the service /// </summary> /// <param name = "filePath"> </param> public void InstallService (string filePath) {Environment. currentDirectory = filePath; Process process = new Process (); process. startInfo. useShellExecute = false; process. startInfo. fileName = "Install. bat "; process. startInfo. createNoWindow = true; process. startInfo. verb = "runas"; // mainly set to start process as an administrator. start ();}

If a service is started after installation, the system prompts that the service cannot be found and the installation program will fail.

The blogger thought of a way to rewrite the OnAfterInstall method and write the startup service in this method:

/// <Summary> /// restart the service /// </summary> /// <param name = "savedState"> </param> protected override void OnAfterInstall (IDictionary savedState) {ServiceController serviceController = new ServiceController ("LandaInformationServiceV9"); serviceController. start (); base. onAfterInstall (savedState );}

So there is no problem!

In this Assembly, you can customize other things you want to do, such as restoring the database.

VII. Postscript

This tutorial ends now. This is also found out by the bloggers over the past few days. If there are any mistakes, please correct them!

Link to the Advanced Installer Website: https://www.advancedinstaller.com /.

I hope this article will help you. If you think this article can help you, just give it a compliment. Your support is the unremitting motive force for the bloggers to continue.

Related Article

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.