The setup projects created in this chapter assume that the .NET Framework is already installed on the target machine. You cannot use Visual Studio .NET setup and deployment projects to package the required .NET Framework along with a setup package. The .NET Framework has to be installed on the target machine by using a .NET Framework redistributable file ( dotnetfx.exe ) that is available through one of the following:
The Windows Component Upgrade CD-ROM that comes with Visual Studio .NET
The Microsoft MSDN Download Center (http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/001/829/msdncompositedoc.xml) or the Microsoft Windows Update Web site (http://windowsupdate.microsoft.com)
Ideally, you would like a Windows application's installation program to perform a test for the availability of the .NET Framework on the target machine, and if the .NET Framework is not already installed, you need to install it by using the .NET Framework redistributable file ( dotnetfx.exe ).
In this exercise, you will learn how to use Microsoft's sample .NET Framework bootstrapper setup.exe file along with a setup package generated through Visual Studio .NET to check for the availability of the .NET Framework on the user 's machine and install it by using the .NET Framework redistributable file if it is not already installed.
Estimated time : 20 minutes.
Open the solution 310C10 . In Solution Explorer, select the NorthwindSetup project.
Right-click the project and select Properties from the shortcut menu. In the NorthwindSetup project's Property Pages dialog box, change the Bootstrapper option to None. Click OK and build the project. Only the NorthwindSetup.msi file is created. It is created in the Release folder of the NorthwindSetup project.
Download the Setup.exe bootstrapper example from http://msdn.microsoft.com/downloads/sample.asp?url=/msdn-files/027/001/830/msdncompositedoc.xml.
Install the downloaded example. It installs two files on your computer: setup.exe and settings.ini . Copy both files to the Release folder of the NorthwindSetup project.
Open the settings.ini file in any text editor. Change its contents as follows :
[Bootstrap] Msi=NorthwindSetup.msi 'LanguageDirectory=jpn 'ProductName=testproductname 'DialogText= 'CaptionText= 'ErrorCaptionText= FxInstallerPath =d:\dotNetFramework
The value of FxInstallerPath is the path where you have stored the .NET Framework redistributable file, dotnetfx.exe . You can change the value to your actual path.
Open the setup.exe file. The installation is bootstrapped by the sample setup.exe file. It first tests for the availability of the .NET Framework. If the .NET Framework is not installed, it uses the path specified in FxInstallerPath to install the .NET Framework. Note that there are no bootstrap files for installing Microsoft Windows Installer because this check is part of the .NET Framework installation and is automatically performed by dotnetfx.exe .
In this chapter, you have learned that the Custom Actions Editor allows you to perform custom actions during the installation process. In this exercise, you create a custom action to run the Northwind database installation script during the installation of the Northwind Web service project. You can use osql , a command-line utility, to run the SQL script. This exercise assumes that you have Microsoft SQL Server installed on your machine.
Estimated time : 20 minutes.
Open the solution 310C10 . Add a Visual Basic .NET Class Library project to the solution. Name the project InstallNorthwind .
Add to the project the Northwind database installation script instnwnd.sql (which is usually available in the Microsoft SQL Server installation directory).
Right-click the project InstallNorthwind and choose Add, Add New Item from the context menu. The Add New Item dialog box appears. Add to the project an Installer Class named InstallNorthwind.vb .
Open the InstallNorthwind.vb file in the code view. Add the following Imports directive:
Add the following code after the Component Designer generated code section in the class definition:
Public Overrides Sub Install(_ ByVal savedState As _ System.Collections.IDictionary) ' Call the Install method of the base ' class MyBase.Install(savedState) Dim strSqlFilePath As String = _ Me.Context.Parameters("Args") ' Run the osql process to run the ' database script Dim psi As ProcessStartInfo = _ New ProcessStartInfo("osql.exe ", _ "-E -i " & "\" & _ strSqlFilePath & "\ ") psi.WindowStyle = _ ProcessWindowStyle.Hidden Try Dim p As Process = Process.Start(psi) p.WaitForExit() Catch ex As Exception ' Throw an InstallException with ' the original exception message Throw New _ InstallException(ex.Message) End Try End Sub Public Overrides Sub Commit(_ ByVal savedState As _ System.Collections.IDictionary) ' Call the Commit method of the base ' class MyBase.Commit(savedState) End Sub Public Overrides Sub Rollback(_ ByVal savedState As _ System.Collections.IDictionary) ' Call the Rollback method of the base ' class MyBase.Rollback(savedState) End Sub Public Overrides Sub Uninstall(_ ByVal savedState As _ System.Collections.IDictionary) ' Call the Uninstall method of the base ' class MyBase.Uninstall(savedState) End Sub
Build the InstallNorthwind project.
Select the NorthwindSetup project in Solution Explorer. Open the File System Editor. Select the Web Application Folder node and add the Primary Output from InstallNorthwind (Active) file to the folder by selecting Action, Add, Project Output.
Select the Web Application Folder node and add the instnwnd.sql file from the InstallNorthwind project to the folder by selecting Action, Add, File.
Open the Custom Actions Editor for the NorthwindSetup project. Right-click the Custom Actions node and select Add Custom Action from the context menu. The Select Item in the Project dialog box appears. Select Primary Output from InstallNorthwind (Active) by navigating to the Web Application Folder. Click OK. The Primary Output from InstallNorthwind (Active) file is added to all four nodes under Custom Actions.
Select the newly added custom action under the Install node. Open the Properties window and set the CustomActionData property to /Args="[TARGETDIR]instnwnd.sql" .
Build the NorthwindSetup project. Install the project. This time, during installation, the Northwind database installation script is also executed.
What is the difference between deploying a private assembly and deploying a shared assembly?
A private assembly is deployed for use by a single application and is deployed within the directory of the application that uses it. A shared assembly is deployed for use by multiple applications. Shared assemblies are signed with a strong name and are usually deployed in the GAC.
What is binding policy? How can you override the default binding policy of the CLR?
Binding policy is a set of rules that defines how the CLR binds to an assembly. The default binding policy of the CLR can be modified using the policy configuration filesapplication configuration file, publisher policy configuration file, and the machine configuration file.
Describe the process by which the CLR binds to a shared assembly.
The CLR first determines the correct version of the assembly that needs to be located by analyzing the policy configuration files. The CLR then checks whether the assembly has already been loaded from one of the previous calls. If not, the CLR searches the GAC for the correct assembly. Upon failure, the CLR checks for the presence of the < codebase > element in the policy configuration files. If there is one, the CLR uses the information in the <codebase> element to locate the assembly.
Otherwise, the CLR searches the assembly in the application's directory structure (in the base directory and in a subdirectory whose name is the same as the assembly itself). If the assembly has culture information, the CLR looks for the assembly in the culture subdirectory.
If all fails, the CLR checks the configuration files for the <probing> element and searches for the assembly in the subdirectories specified by the <probing> element.
What is side-by-side execution?
Side-by-side execution is the ability to run multiple versions of the same assembly simultaneously . The CLR determines which assembly to load for a given application using the assembly manifest of the calling application combined with the three policy configuration filesapplication configuration file, publisher policy configuration file, and the machine configuration file.
What is the purpose of the File System Editor?
The File System Editor provides mapping of the file system on the target machine. The folders are referred to by special names that are converted during the installation process to represent the folders as per the file system on the target machine.
How can you customize the user interface of an installation process?
The User Interface Editor allows you to create your own user interface for the installation process. There are three stages of installation: Start, Progress, and End. The editor allows you to add different types of dialog boxes to each of the different stages. It provides special properties whose values can be evaluated to perform the installation according to the end user's choice.
Where is the GAC located on a machine? How can you add items to the GAC?
The GAC is located in the assembly folder under the Windows folder on a machine. You can view shared assemblies in the GAC by navigating to the assembly folder in Windows Explorer. You can add shared assemblies to the GAC through Windows Explorer, the .NET Framework Configuration tool ( mscorcfg .msc ), the Global Assembly Cache tool ( gacutil.exe ), or the Windows Installer.
What is meant by delay signing?
Delay signing is a process that allows you to place a shared assembly in the GAC by just signing the assembly with a public key. This allows the assembly to be signed with a private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed.
When should you use a merge module project?
Merge modules should be used to package shared components with their related resources, Registry entries, custom actions, and launch conditions. Merge modules cannot be installed directly; rather, they are merged into setup projects.
You have created a database-driven Web service. Using Microsoft SQL Server, you have also generated an installation script for your database. This script is stored in a file named InstData.sql . When the clients deploy the Web service on their servers, the database should be created as part of the installation. You are creating a setup project by using Visual Studio .NET. Which of the following actions should you take to create the database as part of the installation process?
A. You can use the Custom Actions Editor to take custom actions such as database installations during application setup. If you have a component that derives from the Installer class and overrides the Install() method to create databases, it must be added to the Install node of the Custom Actions Editor.
You are creating a setup project for a Windows service. In the Property Pages dialog box for the setup project, you have set the compression property to Optimized for speed. Which of the following options will be true because of this configuration option? (Select the two best answers.)
C and D. Modifying a setup project's Compression property to Optimized for speed does not affect the size or speed of the installed assemblies. Instead, the setup program compresses the assemblies by using a compression algorithm that is optimized for speed. As a result, you have a lower compression ratio, which means you have a large setup package that executes faster.
You have developed a database- intensive Web Service application. When the application is installed on the user's computer, the required database must also be installed. The execution of the program cannot continue without the database. Therefore, if setup of the database fails, you would like to roll back the installation process. Which of the following editors would you use in the setup project to ensure that the database is properly installed on the target machine?
B. The Custom Actions Editor allows you to execute custom actions, such as database installations, while running the setup program. It also has provisions for performing an installation rollback if the installation operation fails.
You have created a .NET Remoting application that uses some components that are not shared by other applications. Each of these components creates its own assemblies, and all these assemblies have strong names associated with them. The application that uses these components is not required to load a specific version of these components. You do not want to store the assemblies in the application's installation folder. Which of the following options is the best approach to store the assembly files for the application's components?
C. If the components are not shared between applications, it is not a good idea to store them in the GAC. You could use the <codebase> element in the application's configuration file, but in that case you must specify a version of the assembly. The applications in question are not specific about versions, so a good place to store the assemblies is in a folder inside the application's installation folderwith its location specified via the <probing> element in the application's configuration file.
You are responsible for maintaining the installation of a Windows service that listens for orders and updates the database. The Windows service uses a serviced component, OrderProcess.dll , which is signed with a strong name. You have version 1.0 of this serviced component that you have installed in the root directory of the application. You later receive a version 2.0 of OrderProcess.dll , which you install in the global assembly cache, as well as the root directory of the application. You reconfigure the application configuration file of the Windows service to redirect version 1.0 calls to version 2.0. Now you receive version 3.0 of OrderService.dll , which you again install in the global assembly cache. You do not reconfigure the application configuration file. Now when you run the Windows service, which version of OrderService.dll is loaded and from which location?
B. As a first step, the CLR tries to determine the version of assembly by analyzing the configuration files. From application configuration files, the CLR knows that it should search for version 2.0 of the assembly instead of version 1.0. Therefore, as a next step when the CLR queries the GAC, it is able to bind to version 2.0 of the assembly.
When you install a Windows application on a target machine, you want to store the ReadMe.txt file in the installation directory selected by the user. You also want to create a shortcut for the ReadMe.txt file on the desktop of the target machine. While creating a setup project, which of the following actions would you take in the File System Editor to achieve this? (Select all that apply.)
A, B, and C. To copy the ReadMe.txt file to the installation directory selected by the user at install time, you would add it to the Application Folder node in the File System on the Target Machine node. To create a shortcut, you first create a shortcut to the ReadMe.txt file stored in the Application Folder node in the File System on the Target Machine node. Then you move this shortcut from the Application Folder node to the User's Desktop in the File System on the Target Machine node.
You have written a component that will be shared among multiple applications. You want to install the component to the GAC. Which of the following tools will you use to achieve this? (Select the two best answers.)
A and B. When you want to install a component to the GAC, you first assign it a strong name. You do this by using the Strong Name tool ( sn.exe ). You can place a strongly named assembly in the GAC by using the Global Assembly Cache tool ( gacutil.exe ).
You are a developer in a large manufacturing company. You are developing a complex inventory control application with a team of 15 developers. You have written two program modules, inv1234.vb and inv5678.vbs , which are generic and will be used from several other applications within the company. You compiled both program modules by using the vbc compiler to produce the inv1234.netmodule and inv5678.netmodule files. You now want to link both compiled modules into an assembly that you will install in the GAC to test some Windows forms that depend on this assembly. You have decided to keep the name of the assembly as InvLib.dll . You do not have access to the private key of the company, but you have access to the company's public key. The public key is stored in a file named BigCoPublic.snk . When the testing is completed, your project manager will use the private key (stored in the BigCoPrivate.snk file) to fully sign all the assemblies in the accounting software application. Which of the following commands would you choose to successfully sign your assembly?
B. You can use the al.exe command to link already compiled modules into an assembly. The process of including a public key in an assembly and signing it with a private key at a later stage is called delay signing. You can perform delay signing on an assembly by using al.exe with the /delay+ switch.
You are using the Installer tool ( installutil.exe ) to install server resources by executing the installer components in three assemblies. You issued the following command:
installutil Assembly1.exe Assembly2.exe Assembly3.exe
During the execution of this command, the installation of Assembly3.exe failed. Which of the following will happen?
D. installutil.exe performs installation in a transactional manner. If one of the assemblies fails to install, installutil.exe rolls back the installations of all other assemblies. So if the installation of Assembly3.exe fails, none of the assemblies will be installed.
You work as a software developer in a large chemical manufacturing company. You create an XML Web Service that provides material safety information to its partners and customers. The Web service has been thoroughly tested using a test server. You now want to deploy the Web service on the company's production server. You do not want to manually configure any settings on the production machine. Which of the following methods of deployment should you choose?
D. When you copy the files for the XML Web service from one computer to another, you might have to manually configure a few things such as the creation of the virtual directory. If you want all these tasks to be automated, you should choose the Web setup projects to create a setup program.
You want to create a customized setup program for a .NET application. One of the screens shown during installation should be available only from the administrative installation of Microsoft Windows Installer. Other setup options should be available for both regular and administrative installations. Which of the following editors would allow you to create such an installation program?
B. You can customize the user interface of an installation program by using the User Interface Editor for both regular and administrative installations.
You have used the native compilation option for several assemblies in your Windows application. During the testing of the application, you found that one of several parameters on the order entry forms is displayed incorrectly. You determined that classes involved in the problem are part of the native image cache. You want to analyze the contents of the native image cache on the user's computer to see if the correct versions of the assemblies are installed there. Which of the following methods could you use to view the contents of the native image cache? (Select all that apply.)
A, B, and C. The native image cache can be viewed with all the listed tools except for the Assembly Binding Log Viewer ( fuslogvw.exe ), which is used to display failed assembly binds.
You work as a software developer for a big pharmacy. You are writing some components that will be shared across several applications throughout the company. You want to place an assembly named CommonComponents.dll in the GAC for testing purposes. You do not have access to the company's private key, but you have stored the company's public key in the assembly manifest of CommonComponents.dll . Which of the following commands are you required to run to place your assembly in the GAC? (Select all that apply.)
A and C. You will have to first turn off the verification for partially signed assemblies. This can be done by using the sn.exe tool with the -Vr switch. Next the assembly can be installed to the GAC using /i switch with the gacutil.exe command.
Your Web service application is already deployed to your company's production Web server when you discover a logic error in one of the Web methods. You have corrected the error and rebuilt the application on the test server. What is the easiest way to transfer the changes to the production server?
C. If a Web service is already installed on IIS, you can simply replace any updated files. ASP.NET will detect the changed files and automatically recompile the pages as clients request them.
You are designing a Windows application that will be downloaded to a user's computer from your company's Web server. After it is installed on the user's computer, the application might request and download more components from the Web site as needed for the user's requirements. The application uses several components that need to be installed in the GAC on the user's machine. You want to sign your components with a cryptographic digital signature, as well as with an Authenticode signature so that the identity of your company is certified through an independent certifying authority. Which of the following options would you use for signing the components before they are packaged for deployment?
C. sn.exe is used to sign an assembly with a cryptographic digital signature, whereas signcode.exe is used to sign an assembly with an Authenticode signature. When both are used together to sign an assembly, you must always use sn.exe before using signcode.exe .
1. The Visual Studio .NET Combined Help Collection:
"Deploying Applications and Components"
"Creating Installation Components"
2. Jeffery Ritcher. Applied Microsoft .NET Framework Programming . Microsoft Press, 2002.
3. Deploying .NET Applications: Lifecycle Guide. www.microsoft.com/downloads/release.asp?releaseid=40545.
4. Microsoft Support WebCast: Microsoft .NET: Deploying Applications with .NET. support.microsoft.com/servicedesks/webcasts/wc091902/wcblurb091902.asp.