What happens if an architect designs a lot of architectural drawings and then does nothing with them? I mean no implementation, no building, just secured inside files. Your code inside your computer are going to be the same as unimplemented design if at the end of the day they are just debugged for errors and then no use in friends computers or just yours seeing its icon in the desktop.
You can make your code and design to the real use and not just debugging by building it to create an assembly file where someone can double-click it and become happy. But for larger commercial applications, this simple approach might not be enough; customers would like you to install the files in the appropriate directories, set up shortcuts and have it in start menu list.
OK! Just make them happy by creating .msi installer files using Setup and deployment projects in Visual Studio, and this is what we are going to show in this tutorial.
DEPLOYMENT PROJECT:
Visual Studio provides extensive help for deployment where by you can create a setup project for your application. In Visual Studio 2010, Microsoft has extended its windows installer, Click Once technology and added Install Shield 2010 limited edition. These three available templates in VS2010 are going to be the discussion in this post.
1. Windows installer:
Windows Installer deployment enables you to create installer packages to distribute to users. Windows Installer deployment is updated in Visual Studio 2010 Professional for the latest .NET Framework versions. You can target the .NET Framework 4 or ASP.NET 4 versions in your windows and Web applications. Additionally, you can check that any version of the .NET Framework is installed on the end-user computer, rather than checking for a specific version of the .NET Framework.
To create a setup project go to create new project>other project type> setup and deployment> visual studio installer. Let us look at these available templates from the picture below;
Resized to 75% (was 670 x 302) - Click image to enlarge
Setup project/ setup wizard:
Builds an installer for a Windows application, setup projects will install files into the file system of a target computer. In addition, a Setup Wizard is available to simplify the process of creating a Setup or Web Setup project.
Web setup project;
Builds an installer for a Web application, the files for a Web Setup Projects are installed into a Virtual Root directory on Web servers. The distinction between Setup and Web Setup projects is where the installer will be deployed.
Merge module project;
A merge module (.msm file) is a single package that contains all files, resources, registry entries, and setup logic necessary to install a component. Merge modules cannot be installed alone, but must be used within the context of a Windows Installer (.msi) file. Merge modules allow you to capture all of the dependencies for a particular component, ensuring that the correct versions are installed. Much the same as dynamic-link libraries allow you to share code between applications; merge modules allow you to share setup code between Windows Installers.
CAB project;
Creates a CAB file for downloading to an earlier Web browser. You can use CAB projects to package ActiveX components that can be downloaded from a Web server to a Web browser.
Unlike the other deployment project types, there are no editors provided for working with Cab projects. Files and project outputs can be added to a Cab project in Solution Explorer, and properties can be set in the Properties window or in the Project Property pages.
Customizing an installer:
If you are using a wizard, things are easy, just don’t forget to put your eye in these two pages;
Resized to 77% (was 655 x 261) - Click image to enlarge
After the wizard has finished, now you have completed to create an installer for your application. Now save all changes and start to build your application, if building completed successfully, build the installer. Go to where you have saved the solution and you will see an installer file inside the debug folder in your setup project directory.
But I think this is not enough for you! You need to go deeper in customization, so follow me in the following issues:
Deployment editors:
The deployment editors are used to configure an installer that you create with a deployment project. Each deployment project includes six editors: File System Editor, Registry Editor, File Types Editor, User Interface Editor, Custom Actions Editor, and Launch Conditions Editor. To open an editor, select a deployment project and the buttons will appear as shown below or alternatively, right-click your deployment project, point to View, and then click the name of the editor that you want to open
Resized to 68% (was 740 x 269) - Click image to enlarge
• File system editor;
When the project is added to the solution, the first thing to be displayed is the file system editor. The picture above shows file system editor. There are three files in it including Application folder where your program will be installed, user`s desktop where a shortcut are placed and a User’s program menu where files in it are shown in start menu.
To add a file to any of these folders right click on it and select add> file. To put shortcut of your application in start menu or desktop go to application folder, right click on primary output from… (Or any other files which you want to create shortcut for them), select create shortcut to… then the shortcut will appear, cut it and paste to the folder where you want a shortcut to appear. Also you can add project outputs in the target folder using the same way explained below just select project output... instead of a file.
• User interface editor;
The user interface editor helps you to customize the installation wizard interface.
Resized to 59% (was 857 x 200) - Click image to enlarge
The User Interface Editor is a tree control containing two sections: Install and Admin. TheInstall section contains dialog boxes that will be displayed when the end user runs the installer; the Admin section contains dialog boxes that will be displayed when a system administrator uploads the installer to a network location. You may change the statements that appear during installation categorized in the three predefined dialog boxes (Start, progress & end).
• Registry editor;
The Registry Editor allows you to specify registry keys and values to be added to the registry of the target computer. By default the Registry Editor displays a standard set of registry keys that correspond with the standard Windows registry keys: HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, and HKEY_PER_USER. For Setup projects, additional keys that match the Manufacturer property for the project are displayed under HKEY_CURRENT_USER\Software and HKEY_LOCAL_MACHINE\Software.
Playing with registry need more experienced person otherwise it may course some trouble in target computer, but you can add or remove keys according to what your project needs.
To add a registry key select a top level node, in the action menu click new key, then type the new name and edit properties of the key in the properties window as necessary.
To add a sub key select a key node, in the action menu point to new and then key and you can edit its properties from the properties window. Also you can remove a key by selecting it and then click Delete from Edit menu. Also you can add string, binary, and DWORD values. During installation the values will be written to the registry and any existing values will be overwritten by the values that you specify.
• Custom actions editor;
Here you can specify additional actions to be performed on the target computer at the end of an installation. Five predefined custom actions are included in Visual Studio to install Event Log, Message Queue, Performance Counter, Service, and Service Process components. When these components are configured as installation components, they are wrapped in an installer class and are recognized by the deployment system as a custom action.
Resized to 93% (was 538 x 382) - Click image to enlarge
The editor contains four folders, each corresponding with a phase of installation: Install Commit, Rollback, and Uninstall which are run in the same order that they are displayed in the editor.
To add custom actions first must be compiled as a .dll, .exe file or .NET framework component and added to a project as a script or assembly before they can be added to a deployment project. Then right click on one of the four folders and chose Add custom action then select your item to be added. If the item hasn't previously been added to the deployment project, click the Add File, Add Output, or Add Assembly button to add the item as a custom action. This also adds the item to your project. To add a custom action to all four folders, select the Custom Actions node in the editor, and choose Add Custom Action.
• File Types editor;
File Types editor allows you to specify document types and associate them with file extensions. In addition, you can specify the verbs or actions for each document type and specify MIME types for the document types for use in browsers.
The File Types Editor contains a single pane with hierarchical list of file types and actions. By default, the File Types Editor contains a single File Types on Target Machine node; new file types may be added beneath that node. There are three steps involved in associating a file type with your application: adding a document type, associating a file extension, and associating an executable file.
To add a document type, right click on File Type on Target Machine and select Add File Type and give it a name. Then you can associate it with file extension by going to its properties and type the extension without precede it by a period (separate multiple extensions by ; ). Then you can set a command by selecting a .exe file associated with.
• Launch conditions editor;
The Launch Conditions Editor allows you to specify conditions that must be met in order to successfully run an installation. For example you may check for the OS version, windows installer components, registry key or even a file if it exists in a target machine.
To add an item to search right click on Search Target Machine and then select an item you want to be searched in the target machine and then set its properties from the propertieswindow. The following pictures from MSDN summaries the properties available:
Resized to 49% (was 1021 x 630) - Click image to enlarge
Resized to 51% (was 999 x 338) - Click image to enlarge
Resized to 51% (was 984 x 216) - Click image to enlarge
Resized to 50% (was 1012 x 292) - Click image to enlarge
To make your application run in any version of .NET framework, right click on Requirement on Target Machine and then click Add .NET Framework Launch Condition, in properties window change Version to Any. There are editors available in setup project in visual studio.
Choosing prerequisites to install:
Sometimes your application may depend on components that must be available in target computer before the installation can take place. If one of those dependent components is not available, an error message will be raised and installation will be aborted!
You can make your user fill happy without a list of error messages, by including some prerequisites to be installed if not available in target computer.
To choose which one to be included in your package, right click on your deployment project and select properties, in the Property Pages dialog box, expand the Configuration Properties node, and then select the Build property page. Click the prerequisite button and make sure that the Create setup program to install prerequisite components box is checked. Then select the prerequisites that you want to install from the Choose which prerequisites to install list.
Resized to 74% (was 682 x 503) - Click image to enlarge
Here you can select example the .NET framework version and windows installer version and other prerequisites from the dialog box.
Down the dialog there is specify the install location for prerequisite, and three radio buttons are available:
Resized to 48% (was 1045 x 193) - Click image to enlarge
This capability to automatically detect the existence of components during installation and install a predetermined set of prerequisites is referred to as bootstrapping and the component that performs it is called the generic bootstrapper which uses bootstrapper packages to install the prerequisite components on the target computer.
The default location of the bootstrapper packages is stored in the registry keyHKEY_LOCAL_MACHINE\Software\Microsoft\GenericBootstrapper\4.0\Path. Changing this path will change the location in which the Prerequisites Dialog Box looks for bootstrapper packages.
Creating installer for 64 bit platform:
The deployment tools in Visual Studio allow you to create installers for 64-bit applications and components. The TargetPlatform Property of a deployment project determines whether an installer will target a 32-bit or a specific 64-bit platform. The target platforms are x86 for 32-bit platforms, x64 for computers supporting the AMD64 and EM64T instruction sets, and Itanium for the 64-bit Itanium processor.
In general, 32- and 64-bit Microsoft Installer (MSI) packages are treated in the same way except for how Windows Installer treats folder variables such as Program Files and System Folder, and how it writes components into the registry or GAC. To create a 64 bit installer select your setup project and in the properties window change TargetPlatform to eitherItanium for an Intel Itanium 64-bit platform, or x64 for any other 64-bit platform (such as AMD64 and EM64T instruction sets).
Security in windows installer:
Windows Installer can use digital signatures to detect and correct corrupted resources. In Windows XP, Windows Installer is integrated with Software Restriction Policy to restrict both administrators and non-administrators from running program files based on the path, URL zone, hash, or publisher criteria.
Also you can sign an assembly which gives an application a unique identity that other software can use to identify and refer explicitly to it (process also called strong-name signing). A strong name consists of its simple text name, version number, culture information (if provided), plus a public/private key pair. This information is stored in a key file; this can be a Personal Information Exchange (PFX) file or a certificate from the current user's Windows certificate store.
To sign an assembly, right click on project and click properties, from the project form click the signing tab and then select the sign the assembly. From a Choose a strong name key file drop-down list, select either <new…> if you want a new key file or <browse…> for an existing file. For new file enter a name and password in the Create strong Name key.
Resized to 72% (was 704 x 441) - Click image to enlarge
Now rebuild your application and then a setup project to get a .msi file ready for installation.
2. ClickOnce technology:
To make a ClickOnce application available to users, you must publish it to a Web server, file share, or removable media. You can publish the application by using the Publish Wizard; additional properties related to publishing are available on the Publish page of the Project Designer.
Resized to 66% (was 760 x 507) - Click image to enlarge
Publish properties can be set using the Publish Wizard but only a few of the properties are available in it, all other properties are set to their default values. Now let’s look at the properties that can be changed in this Publish page:
• Publish location;
You can publish the application to a Web site, FTP server, or file path. Type the location as a disk path, file share, FTP site, or Web site URL, or click the Browse button to browse for the location.
• Disk path: Specify a local disk path from which you can copy the application to a CD-ROM or DVD-ROM. The path can be a relative or absolute path in standard Windows format, for example: C:\Deploy\DIC.
• File share: Specify a file share by using a Universal Naming Convention (UNC) path from which the application will be deployed, for example: \\ServerName\DIC\.
• FTP server: Specify the path of a Web site from which the application can be downloaded by using FTP, for example: ftp://ftp.fileServer.com/DIC.
• Web site: Specify the URL of a Web site from which the application can be downloaded by using HTTP, for example: http://www.website.com/DIC.
• Install mode and settings;
First you have to say if the application is available offline or not (online only). If you select The application is available online only, then it will be run directly from the publish location without creating a shortcut on the start menu. Otherwise the application will be available even if a user is disconnected from the network and a shortcut will be available on start menu.
Also you can click on Prerequisites.. button to specify which prerequisite to be included. The prerequisite dialog is the same as the one explained above in windows installer.
Father more, if you set your application to be available offline, you can set application updates either automatically or programmatically. Also you can configure the application to check for updates automatically before the application starts, or at set intervals after the application starts. In addition you can specify a minimum required version; that is, an update is installed if the user's version is lower than the required version.
• Publish version;
To increase publish version, increase major, minor, build or revision version number according to what updates you have made! Changing the number in these fields causes the application to be published as an update. Also you can clear the Automatically increment revision with each publish if you don’t want visual studio to automatically increment the clickOnce publish version.
Then click on Publish Now to publish your application after making sure that all settings of your application have already been set correctly.
Security in ClickOnce:
ClickOnce security relies on Authenticode certificates to determine whether an application should be installed, a step known as a trust decision. Application and deployment manifests that describe an application can be signed with a certificate to prevent tampering. Domain administrators can configure certificates to be trusted at the enterprise or machine level. If certificates are not trusted at the time of installation, ClickOnce deployment can be configured to ask users to make trust decisions. Once an application is installed, ClickOnce restricts the application permissions and actions as defined by the Internet, Local Intranet, or custom zones.
3. InstallShield 2010 Limited Edition:
Microsoft has partnered with Flexera, makers of InstallShield to create InstallShield LE for Visual Studio 2010. This is a Visual Studio extension you can download and use today to build Windows installer-based deployment packages for your application that can be deployed on the Windows platform. It provides comparable functionality to the Visual Studio Installer project but in addition, you get the easy to use, modern, graphical development environment of InstallShield, as well as the ability to build your deployment projects using Team Foundation Server.
First time users need to enable InstallShield LE by downloading and installing it. Go to create new project and select InstallShield. After creating the project the template will bring you to registration page and then the download link. Once you have installed the product, the new project dialog will provide an option to create an installShield LE project. Now after creating a new project, the first form is where we start now:
Resized to 46% (was 1090 x 555) - Click image to enlarge
At the bottom of the screen are the steps to the installation project and I am going to talk a little on them. (Using the next button will make sure you have passed on all steps)
Application information;
Here you will feel the basic information about the application including application name and version.
Installation requirements;
Specify the prerequisites that must be installed including version of OS and .NET framework. Customer prerequisites can be defined under create a custom software condition
Installation architecture;
This step is disabled in the Limited Edition. In the other editions different features can be defined for users to choose what sections they want installed.
Application files;
The application files such as project output can be added here (don’t forget to add primary output).
Application shortcuts;
Here you can define shortcuts for Start menu and desktop. Click on New, on the dialog selectprogramFilesFolder>your company name>product name and you will find the primary output of your application, then tick on where you need the shortcut to be available and an icon if any.
Application registry;
If the application requires any registry entries, they can be defined here.
Installation interview;
This defines the user interface by specifying which dialogs should be displayed to users and which should not. Also you can create a custom dialog but this feature is not available in limited edition.
Also in solution explorer, there are many other features and explanation about advanced issues in deployment. You can view them for more information and customization.
Now you can build it to get a .msi file for installation which can be found fromSetupName\SetupNama\Express\DVD-5\DiskImages\DISK1.
NOTE: If you made any changes to your application, first rebuild your application before building the installer.
I finally installed my application in my computer;
Resized to 98% (was 511 x 384) - Click image to enlarge
This is the end of this tutorial about setup and deployment in VS2010. Good to say is that many concepts from this tutorial I studied them from Microsoft Developer Network Library. Thanks, and for any comments just feel free to help the DIC community!
沒有留言:
張貼留言