Apply Your Knowledge

   


Exercises

10.1 Using Microsoft's Sample .NET Framework Bootstrapper

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.

  1. Open the solution 310C10 . In Solution Explorer, select the NorthwindSetup project.

  2. 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.

  3. Download the Setup.exe bootstrapper example from http://msdn.microsoft.com/downloads/sample.asp?url=/msdn-files/027/001/830/msdncompositedoc.xml.

  4. 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.

  5. 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.

  6. 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 .

10.2 Creating a Database Script During Installation

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.

  1. Open the solution 310C10 . Add a Visual Basic .NET Class Library project to the solution. Name the project InstallNorthwind .

  2. Add to the project the Northwind database installation script instnwnd.sql (which is usually available in the Microsoft SQL Server installation directory).

  3. 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 .

  4. Open the InstallNorthwind.vb file in the code view. Add the following Imports directive:

     Imports System.Diagnostics 
  5. 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 
  6. Build the InstallNorthwind project.

  7. 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.

  8. Select the Web Application Folder node and add the instnwnd.sql file from the InstallNorthwind project to the folder by selecting Action, Add, File.

  9. 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.

  10. Select the newly added custom action under the Install node. Open the Properties window and set the CustomActionData property to /Args="[TARGETDIR]instnwnd.sql" .

  11. Build the NorthwindSetup project. Install the project. This time, during installation, the Northwind database installation script is also executed.

Review Questions

1:

What is the difference between deploying a private assembly and deploying a shared assembly?

A1:

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.

2:

What is binding policy? How can you override the default binding policy of the CLR?

A2:

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.

3:

Describe the process by which the CLR binds to a shared assembly.

A3:

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.

4:

What is side-by-side execution?

A4:

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.

5:

What is the purpose of the File System Editor?

A5:

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.

6:

How can you customize the user interface of an installation process?

A6:

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.

7:

Where is the GAC located on a machine? How can you add items to the GAC?

A7:

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.

8:

What is meant by delay signing?

A8:

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.

9:

When should you use a merge module project?

A9:

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.

Exam Questions

1:

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?

  1. Create a component that derives from the Installer class. Override its Install() method to create the database. Add the component to the Install node of the Custom Actions Editor in the setup project.

  2. Create a component that derives from the Installer class. Override its Install() method to create the database. Add the component to the Commit node of the Custom Actions Editor in the setup project.

  3. Copy the InstData.sql file to the Application Folder on the File System on Target Machine by using the File System Editor. Add InstData.sql to the Install node of the Custom Actions Editor in the setup project.

  4. Create a component that derives from the Installer class. Override its Install() method to create the database. Add the component to the Launch Conditions Editor in the setup project.

A1:

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.

2:

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.)

  1. All assemblies in the application will be precompiled to native code so that they run faster.

  2. The resulting assemblies will be larger.

  3. The setup package will be larger.

  4. The setup project will run faster.

A2:

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.

3:

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?

  1. File System Editor

  2. Custom Actions Editor

  3. Launch Conditions Editor

  4. Registry Editor

A3:

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.

4:

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?

  1. Store the components in the GAC.

  2. Store the components anywhere you like and specify the path to them by using the <codebase> element in the application's configuration file.

  3. Store the assemblies in one of the subdirectories under the application's installation directory and specify this subdirectory as part of the <probing> element in the application's configuration file.

  4. Store the components in the Windows System32 directory.

A4:

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.

5:

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?

  1. Version 1.0 from the root directory of the application

  2. Version 2.0 from the global assembly cache

  3. Version 2.0 from the root directory of the application

  4. Version 3.0 from the global assembly cache

A5:

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.

6:

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.)

  1. Move the shortcut to the ReadMe.txt file from the Application Folder node to the User's Desktop in the File System on the Target Machine node.

  2. Add the ReadMe.txt file to the Application Folder node of the File System on the Target Machine node.

  3. Create a shortcut to the ReadMe.txt file that is available in the Application Folder node of the File System on the Target Machine node.

  4. Add the ReadMe.txt file to the User's Desktop node in the File System on the Target Machine node.

  5. Move the shortcut to the ReadMe.txt file from the User's Desktop node to the Application Folder in the File System on the Target Machine node.

A6:

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.

7:

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.)

  1. sn.exe

  2. gacutil.exe

  3. ngen.exe

  4. installutil.exe

A7:

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 ).

8:

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?

  1.  al.exe inv1234.netmodule,inv5678.netmodule /delaysign /keyfile:BigCoPublic.snk /out:InvLib.dll 
  2.  al.exe inv1234.netmodule,inv5678.netmodule /delaysign+ /keyfile:BigCoPublic.snk /out:InvLib.dll 
  3.  al.exe inv1234.netmodule,inv5678.netmodule /delaysign- /keyfile:BigCoPublic.snk /out:InvLib.dll 
  4.  csc.exe inv1234.vb,inv5678.vb /delaysign /keyfile:BigCoPublic.snk /out:InvLib.dll 
A8:

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.

9:

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?

  1. Only Assembly1.exe will be installed.

  2. Only Assembly2.exe will be installed.

  3. Both Assembly1.exe and Assembly2.exe will be installed.

  4. None of the assemblies will be installed.

A9:

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.

10:

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?

  1. FTP the files from test server to the production server.

  2. Use the XCOPY command to copy all your files to the production server.

  3. Use the Visual Studio .NET Copy Project command to copy all the project files to the production server.

  4. Create a Web setup project for your application and use the setup program to deploy the application on the production machine.

A10:

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.

11:

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?

  1. File System Editor

  2. User Interface Editor

  3. Custom Actions Editor

  4. Launch Conditions Editor

A11:

B. You can customize the user interface of an installation program by using the User Interface Editor for both regular and administrative installations.

12:

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.)

  1. Use the Assembly Cache Viewer Shell Extension ( shfusion.dll ).

  2. Use the Global Assembly Cache tool ( gacutil.exe ).

  3. Use the Native Image Generator tool ( ngen.exe ).

  4. Use the Assembly Binding Log Viewer ( fuslogvw.exe ).

A12:

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.

13:

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.)

  1. sn.exe Vr CommonComponents.dll

  2. sn.exe Vu CommonComponents.dll

  3. gacutil.exe /i CommonComponents.dll

  4. gacutil.exe /u CommonComponents.dll

A13:

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.

14:

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?

  1. Use FTP to move the changed files to the production server. Restart the WWW service on the production server.

  2. Build a Windows Installer project to install the entire application. Run the Installer project on the production server. Restart the WWW service on the production server.

  3. Use FTP to move the changed files to the production server. Do not restart the WWW service on the production server.

  4. Build a Windows Installer project to install the entire application. Run the Installer project on the production server. Do not restart the WWW service on the production server.

A14:

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.

15:

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?

  1. Use sn.exe to sign the assemblies.

  2. Use signcode.exe to sign the assemblies.

  3. Use sn.exe followed by signcode.exe to sign the assemblies.

  4. Use signcode.exe followed by sn.exe to sign the assemblies.

A15:

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 .

Suggested Readings and Resources

1. The Visual Studio .NET Combined Help Collection:

"Deploying Applications and Components"

"Deployment Walkthroughs"

"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.


   
Top


MCAD. MCSD Training Guide (Exam 70-310. Developing XML Web Services and Server Components with Visual Basic. NET and the. NET Framework)
MCAD/MCSD Training Guide (70-310): Developing XML Web Services and Server Components with Visual Basic(R) .NET and the .NET Framework
ISBN: 0789728206
EAN: 2147483647
Year: 2002
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net