Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 52 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
52
Dung lượng
0,94 MB
Nội dung
Table 5.1 The Checkbox Dialog Properties PROPERTY PURPOSE CheckboxNLabel The text displayed next to the check box, describing the option you are providing. CheckboxNProperty A name for the property that represents that value stored in the check box. This name will be referenced by the Installer elsewhere and must be all uppercase. CheckboxNValue The initial value of the check box, Checked or Unchecked. CheckboxNVisible Indicates whether or not the control is visible on the form. We are using only a single check box in our case, so make sure you set the Visible property of all but the first check box to false. The rest of the settings in the Properties window should be adjusted as shown in Figure 5.24. Note the name we have supplied in the Checkbox1Property field, BINSTALLDB. We will use this name later to refer to the check box, allowing us to reference the value the user selected. That takes care of setting up and defining our dialog. Now we have to make use of the check box we provided to the user. We will set a File Condition that will only install the database file if the check box is on. Return to the File Editor and select the prj02.mdb file. Enter the following condition into the Condition field of the Properties window: BINSTALLDB = 1 If this condition equates to true, meaning that the check box we created is, in fact, checked, the file will be installed. Otherwise, it will be ignored. Adding a Custom Action The Windows Installer gives you the opportunity to execute any code of your own when an installation task (deployment, rollback, uninstall, etc.) has completed. You can either use a canned action that comes with the installation tools or write custom code of your own. To illustrate the process, we are going to create a simple custom process that displays a Thank You message box to users, stating that we appreciate that they have installed our bug-tracking product. You can create any sort of executable that you like and run it when the installation is over. I’m going to show you how to build a basic executable shell that you can use to launch other processes. Using this simple shell, you could write all sorts of utilities that would be useful for an installation. Let’s build the custom action quickly using a step-by-step process. We’ll start by building the program we want to run during the custom action, and then we’ll add it to the deployment project. The instructions follow: 186 Project 5 1. Create a new project in Visual Studio. It should be of the Class Library type, and you should name it ThankYou. 2. In the Solution Explorer, delete the item called Class1.vb. 3. Right-click on the project name in the Solution Explorer, and from the context menu, select Add Module. When the dialog appears, name it ThankYouModule and click OK. This creates an empty namespace for us to work in, 4. Add the code we want to execute. It looks just like this: Public Sub Main() MsgBox(“We at Vulture Corporation wanted to say a “ & _ “special thanks for taking the time to install “ & _ “our bug-tracking system.” & vbCrLf & vbCrLf & _ “Feel free to contact our customer support line “ & _ “at (123) 555-1234 should you have any questions.” & _ vbCrLf & vbCrLf & _ “Good luck and good code!” MsgBoxStyle.Information, _ “Thanks!”) End Sub The Public Sub Main is our standard entry point. 5. In the Solution Explorer, select the project, right-click on it, and select Properties from the context menu. Set the Output Type to Windows Application, and the Startup Object to Sub Main. 6. Save the project and build it. We have created a simple Windows EXE program that displays a message box and has no other UI. You can use the same tech- nique, replacing our message box code with any code you like. 7. Test the application by locating ThankYou.exe in Windows Explorer and executing it. It should display our message box and then go away. 8. Close the ThankYou project and Load the deployment project. In the File Editor, select the Add Assembly option and add our ThankYou.exe program to the file list. 9. In the Custom Actions Editor, select the Commit item from the event tree and right-click on it. Select the Add Custom Action option. In the selection dialog, open the Application Folder and choose the ThankYou.exe program that we just added using the File Editor. Click OK, and the new action should appear in the tree underneath the Commit event. 10. Make sure the new action, ThankYou.exe, is selected and examine the properties window for that item. Change the value of the property called InstallerClass to false. 11. Save the deployment project and build it. You have now added a custom action to your deployment. When you execute the installation, the custom action will run at approximately the end of the installation operation. Deployment Packages 187 TEAMFLY Team-Fly ® Building and Running the Installation There is one last setting to make. On the toolbar, select Release mode. And now that everything is configured, you can build the installation. Select Build from the Build menu. The tools build your installation package, detailing the files it is adding in the Output window. Take a look at this to see some of the items in the runtime that are being added for you. When the installation build is complete, execute it by browsing to the Release direc- tory under the project directory and double-click the MSI file. This file type is associ- ated with the Microsoft Installer Engine and will run without a specific EXE. This can be a useful deployment feature. For one thing, the installation package is a little smaller because the engine is not part of the deal. Additionally, some Web site admin- istrators will not allow EXE files to be placed on their servers as available downloads for security purposes. MSI files, lacking the EXE extension, can be placed there without fear. Run the execution and take a look at it. The welcome screen makes a nice first impression, especially with our new banner graphic. Figure 5.25 shows the new wel- come screen with the new banner and our text updates. The next dialog is our custom options dialog, where you can see the check box that provides the database installation option. Figure 5.26 shows what it looks like. Leave the box checked and click Next. Figure 5.25 The new installation welcome dialog. 188 Project 5 Figure 5.26 The customized checkbox dialog. The installation dialog box is next, and it looks pretty normal. One interesting fea- ture of this dialog is the Disk Cost button, which is provided free. A click of this button will display a dialog for the user that details how much disk space the installation will take. It is illustrated in Figure 5.27. Figure 5.27 The Disk Cost dialog. Deployment Packages 189 Finish everything else up and the installation begins to run. When it’s all over, the custom action we created launches the browser and loads our advertising page. The application is completely installed, including uninstall information in the Add/Remove Programs control panel. If we were to run our installation package again, without first uninstalling it, the UI we see would be different. We get a wizard panel that asks us if we want to uninstall or repair the existing installation, which it will do for us if selected. Installing on Windows 9x The Windows Installer engine is included as part of the Windows 2000, Windows XP, and Windows ME operating systems. However, if you need to deploy your application on Windows 95 or Windows 98, you would need an actual executable program to run the installation. Microsoft has taken care of this need by providing you with an option to include the Windows Installation Bootstrap along with your deployment package. This option adds a few extra files into your release or debug deployment directory when the package is built. Instead of running the MSI file, you run the Setup.exe pro- gram. This is a runtime version of the installation engine that you can use on Windows platforms that do not have the engine built in. When you create your deployment media, or move your deployment files to a network, simply include these few extra files and anyone will be able to install your program. Note that, although Windows ME includes the installation engine, it may not include the same version, 1.5, that comes with Visual Studio .NET. If it does not, clients without it will have to use the setup.exe program instead. Project 5c: Web Setup Web Setup projects allow you to deploy projects to an IIS Web server. I will be illus- trating a slightly different method of creating a deployment project: using Project Outputs, which allows you to add a deployment project to your main project. This not only keeps the two projects together, but it makes it easier to add the correct files to the installation project. We will be deploying the bug-tracking Web service that we built in Project 3 to a Web server (make sure you have one around). Begin by opening the project file for prj03 in Visual Studio. From the file menu, add a new project to the current solution. In the New Project dialog select the Web setup project type, and name it prj03setup. Click Next, and in the content selection dialog, check these options: ■■ Primary output ■■ Debug symbols ■■ Content files 190 Project 5 Figure 5.28 The Web setup content options dialog. Figure 5.28 shows these selections checked. This dialog lists all the outputs from the primary project in the solution, in this case, the Web service. Click Next to move on, and click Next again to clear the Additional Files dialog. Click Finish to create the project. The deployment project has been added to our solution, alongside our primary project. When you build the solution (go ahead, try it now), it will build your primary project first and then the deployment project using the outputs from the pri- mary project. All that remains is to run the installation for the Web service. Run through the instal- lation, which should deploy the Web service to your instance of IIS. You can test it out by pointing to the Web site it created, like this (assuming you installed it to your local machine): http://localhost/prj03setup/ProblemLogger.asmx The successful execution will look like Figure 5.29. If it does not run properly, you may need to adjust the properties of the Web site in the IIS Admin tool. Change the execute permissions on the prj03setup to Scripts and Executables, as shown in Figure 5.30. Deployment Packages 191 Figure 5.29 Successful execution of the deployed Web service. Figure 5.30 Adjusting the Web service execution permissions. 192 Project 5 That’s it for a Web setup deployment. Very simple, especially for setting up a Web service. We don’t have to understand much about the deployment of a Web application or the intricacies of IIS. The setup tools know it all. Enhancing the Project You’ve seen a lot of deployment capabilities and options in this project, but there are many more. Buried in the Installer tools documentation are features such as the ability to create CAB file projects for the deployment of ActiveX controls; adding splash screens, user registration, read me, or other dialogs; registry manipulations; and tons of low-level details that make fine-tuning your control over your deployment a breeze. Although the installation tools won’t handle every situation you can throw at it, it’s orders of magnitude better than the tools that previously came with Visual Studio. There is a lot to cover in the topic of deployment and plenty of opportunities to use some of the capabilities we didn’t get to, including: Write another custom action. For the Web service deployment, create a custom action to actually create the database it needs in SQL Server. A little code and a couple of SQL scripts would take care of it. Make the Merge Module global. With a little work, you can rebuild the prj01classes component as a strongly named component. This would allow you to install it in the Global Assembly Cache, available for use by other applications. Add some splash. Create a splash screen and add it to your installation project. You could do the same thing with a read me file, or even add another check box that would ask users if they want to see the read me. Register a user. Add functionality to handle user registration to the project. You can add custom dialogs to the project that make a great starting point for letting users register your product. WHAT’S COMING NEXT Enter the world of ASP.NET development when we build a customizable Web portal. It will be an action-packed tour through ASP.NET, including Web development, a new ADO.NET trick or two, and how to tune the project to suit your own needs. Deployment Packages 193 [...]... the data grid to the table in our data set The DefaultView property of our DataTable is an instance of a DataView object that exposes all of the columns of the table You can programmatically create other DataView objects to bind objects to a subset of the columns in your DataTables The DataView object is one of scores of objects that are supported by the data binding engine Actually, any object that... pages that have a clearer separation of content from code and are easier to maintain; your code looks more like traditional code than script that generates HTML This is accomplished by the abstraction layer created between you and the HTML you’re generating by the ASP.NET Framework ASP.NET Framework maintains state for you Do you ever have to post to the server to apply validation logic to a data entry... a whole using the WebPortalTemplate document We will start with the content display areas and then move on to the configuration areas This will allow us to first build static content areas based on different types of data stores (XML and database data) and then move on to building interfaces that update our database data After we have the different display and configuration areas built, we’ll move on... updated with the URL of our Web application You can do development on a local machine or on another machine that has the ASP.NET Framework installed Put the machine name into the Location text box, and click OK Visual Studio NET will now create a new virtual root on the Web server we have chosen and will create some template files and add them to the new IIS application Configuration of the application... it can load an XML document as easily as it can a relational data source 2 Once our data set is created, we can use the data binding services built into ASP.NET to transform it into HTML Because of the abstraction the data set introduces between our XML and how we deal with it, this will work very much the same way as it would for relational data 3 The DataGrid object is the ASP.NET Web control we’ll... object Need to generate an HTML table based on a SELECT statement? Set the DataSource property of a DataGrid object and call DataBind on that object The work of HTML generation is done for you, under the hood, by these objects Does this all sound like a strange new environment? As we start to examine some code and create our own ASP.NET pages, you’ll see that it’s not really that difficult at all And once... the page in response to the menu choices our users make ✄ You Will Need ✔ Visual Basic NET ✔ A basic knowledge of Visual Basic NET and Active Server Pages ✔ SQL Server ✔ Functional IIS installation What Is ASP.NET? ASP.NET is an entirely new framework for the development of scalable Web applications IIS can be configured to delegate requests for different types of files to different subsystems installed... and iterating the rows in the resultset to generate a TD cell for each column of data in your recordset? Well, those days are over Now you simply bind a data grid to a resultset and call the data binding engine The data grid does the rest for you We’ll be taking a closer look at this a bit later Support for Scalability Access to the full language features of Visual Basic NET is not only a great benefit... that are retrieved from memory The cache can be invalidated after a time out, when a file changes (great for caching parsed XML docs), or programmatically This allows you to store information that’s expensive to retrieve or calculate in memory, where it’s instantly available until some dependency changes and the information needs to be retrieved or calculated again Web Portal with ASP.NET Configuration... created by the data set to model this data depend entirely on the structure of the document If we had a more complex document with nested elements and hierarchies, we would get more than one corresponding table object to model the document in relational form For this simple document the data set will decide to create only one table It will have a column for each attribute on the MenuItem elements A DataRow . Will Need ✔ Visual Basic .NET ✔ A basic knowledge of Visual Basic .NET and Active Server Pages ✔ SQL Server ✔ Functional IIS installation What Is ASP .NET? ASP .NET is an entirely new framework for. box that provides the database installation option. Figure 5. 26 shows what it looks like. Leave the box checked and click Next. Figure 5. 25 The new installation welcome dialog. 188 Project 5 Figure. created between you and the HTML you’re generating by the ASP .NET Framework. ASP .NET Framework maintains state for you. Do you ever have to post to the server to apply validation logic to a data