Create a desktop shortcut for a Web installation project and rewrite the installation class

Source: Internet
Author: User
ArticleDirectory
    • 1. Web installation project deployment
    • Ii. Rewrite the installation class:
    • 3. Add Desktop shortcuts and icons for Web Installation Projects
    • Iv. URL File Content
1. Web installation project deployment 1. New:

Create a project-install and deploy a project-web installation project

2. Deployment:

(1) In the file system view, right-click the project and choose View> file system. You can also click the shortcut icon in the upper part of Solution Explorer.
(2) In "Web ApplicationsProgramFolder "to add files, such as aspx files, ICO files, Bin directories and files, images directories and files
(3) set virtual directory properties, right-click "Web application folder" and select Properties, generally, you only need to modify the default document "defaultdocument" and the virtual directory name "virtualdirectorly" (if there are multiple virtual directories
(4) The web installation project does not provide the "user program menu" by default. You need to create the menu by yourself: Right-click "File System on the target computer-add special folder-user program menu"
(5) by default, the Web installation project does not have a user desktop directory. The method is the same as above.
Right-click "File System on the target computer-add special folder-web custom folder" and add Multiple folders one by one, these many virtual directories can only be configured with attributes such as names during design, but cannot be controlled during installation)

Supplement:

When deploying a web project, you can add a website in either of the following ways:
① Release your website first, add the published pages one by one, and add folders such as images in the installation and deployment project, and then add the files under it.
② Add project output to the installation and deployment project and select your website. However, in this case, all the files on your website, including. CS files, will be packaged as they are, which is not very good.

Ii. Rewrite the installation class: 1. Purpose:

After the installation and deployment project is generated, the installation class completes some custom operations when it is "installed", "submitted", "rolled back", and "uninstalled ".

2. Create:

(1) create a class library project
(2) Delete the original class file in the class library and create an "Installer class" ("Add new project" with this template)
(3) custom method: This installation class references system. configuration. Install. dll and using system. configuration. Install and inheritance: installer.
In the custom method, override is used for the install, uninstall, commit, and rollback methods.

3. Usage:

After the creation, it is not effective and must be used together with the installation and deployment project.

Method 1:

(1) Add the class library project as "project output-main output" in the installation and deployment project"
(2) Click "Install", "Submit", and "Roll Back" in "View-custom operations" of the installation and deployment project ", "Uninstall" and other operations "right-click to add custom operations" and select the class library project output just added

Method 2:

(1) Compile the class library and generate. dll
(2) Click "Install", "Submit", and "Roll Back" in "View-custom operations" of the installation and deployment project ", "Uninstall" and other operations "right-click to add custom operations", select a file, and browse to the edited file. DLL

Now, the installation class you wrote will take effect in the "installation", "Uninstall", "rollback", and "Submit" process!

3. Add Desktop shortcuts and icons for Web installation projects. 1. Web installation projects are special to general installation and deployment projects:

(1) A web installation project cannot create shortcuts in its own website project. URL File (Note :. lnk is also a shortcut file, but installation and deployment projects cannot be added. the lnk file can be added. URL File)
(2) by default, no user desktop or user program menu is added for Web installation projects. To add some special operations in "File System View", right-click and choose "add special folder ".
(3) during the installation of the Web installation project, the user dynamically sets the "virtual directory. http: // localhost/*** cannot be disabled in the URL file. It can only be dynamically created during the custom "Install" operation through the "installation class ".

2. Create an "installation class" and add it to "installation" under "Custom operations" of the Web installation project

The content is as follows:

Using system;

Using system. Collections. Generic;

Using system. componentmodel;

Using system. configuration. Install;

Using system. IO;

Using system. directoryservices; // operate the IIS virtual directory

Namespace testinstallclb

{

[Runinstaller (true)]

Public partial class installer2: Installer

{

Public installer2 ()

{

Initializecomponent ();

}

Public override void install (system. Collections. idictionary statesaver)

{

// Create a desktop shortcut and icon, and generate a network shortcut with. url

// Install the SDK first, because the installation directory is available only after installation.

Base. Install (statesaver );

// Obtain the physical directory for software installation, for example, D: \ Inetpub \ wwwroot \ endy_web \ installclass. dll

String fname = system. reflection. Assembly. getexecutingassembly (). location;

// You can also obtain the physical directory for software installation, which is the same as the preceding result, for example, D: \ Inetpub \ wwwroot \ endy_web \ installclass. dll.

// String fname2 = context. Parameters ["assemblypath"];

String [] SZ = fname. Split (New char [] {'\'});

Streamwriter Sw = new streamwriter (file. Open (environment. getfolderpath (environment. specialfolder. Exclude topdirectory) + "\ test site. url", filemode. Create, fileaccess. Write ));

Sw. writeline ("[internetshortcut]");

Sw. writeline ("url = http: // localhost/" + SZ [Sz. Length-2]);

Sw. writeline ("iconfile =" + fname. substring (0, fname. lastindexof ("\") + "\ logo. ICO ");

Sw. writeline ("iconindex = 0 ");

Sw. Flush ();

Sw. Close ();

// Create a shortcut and icon for the user "program" menu, and generate a network shortcut with. URL (the path must be consistent with the user program directory added on the Interface)

/* Process the "Start-program" directory location, because the default specialfolder. programs will be under the current user's program directory, and we will process it to the all user program directory,

Because when you add an uninstall shortcut to a web deployment project, right-click the file system view and choose add special folder> User's 'project' menu to add it to the all user program directory, therefore, the processes created in the following steps must be consistent with those added on the interface,

At the same time, when added to the all user program directory, all user programs will have */

String STR = environment. getfolderpath (environment. specialfolder. Programs );

String [] arr = Str. Split (New char [] {'\'});

Arr [arr. Length-3] = "all users ";

String T = "";

Foreach (string I in ARR)

{

T + = I + "\\";

}

Streamwriter SWR = new streamwriter (file. Open (t + "test site. url", filemode. Create, fileaccess. Write ));

SWR. writeline ("[internetshortcut]");

SWR. writeline ("url = http: // localhost/" + SZ [Sz. Length-2]);

SWR. writeline ("iconfile =" + fname. substring (0, fname. lastindexof ("\") + "\ logo. ICO ");

SWR. writeline ("iconindex = 0 ");

SWR. Flush ();

SWR. Close ();

}

Public override void uninstall (system. Collections. idictionary savedstate)

{

Base. Uninstall (savedstate); // uninstall the SDK first.

// Delete the virtual directory [unavailable due to a problem]

// System. directoryservices. directoryentry dirroot = new directoryentry ("IIS: // localhost/w3svc/1/root ");

// Directoryentry dirport = dirroot. Children. Find ("endy_web", "iisvirtualdir ");

// Dirport. Invoke ("appdelete", true );

// Dirroot. commitchanges ();

// Delete the installation folder [unavailable due to a problem]

// String fname = context. Parameters ["assemblypath"];

// If (directory. exists (fname. substring (0, fname. lastindexof ("\\"))))

//{

// Directoryinfo di = new directoryinfo (fname. substring (0, fname. lastindexof ("\\")));

// Foreach (fileinfo F in Di. getfiles ())

// F. Delete ();

// Di. Delete ();

//}

}

}

}

Iv. URL File Content

After the client is installed, the desktop will generate a shortcut ("My test software. url" does not actually see the extension). Open the content in Notepad as follows:
[Internetshortcut]
Url = http: // localhost/endyweb
Iconfile = c: \ inetput \ wwwroot \ endyweb \ logo. ICO
Iconindex = 0

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.