Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))

Building an Executable File

Your last task in this chapter is to complete the development process and create an application for Windows, or an executable file. Windows applications created with Visual Studio have the file name extension .exe and can be run on any system that contains Microsoft Windows and the necessary support files. (Visual Basic installs these support files—including the .NET Framework files—automatically.) If you plan to distribute your applications, see “Deploying Your Application” later in the chapter.

At this point, you need to know that Visual Studio can create two types of executable files for your project: a debug build and a release build.

Debug builds are created automatically by Visual Studio when you create and test your program. They are stored in a folder called bin\debug within your project folder. The debug executable file typically contains debugging information that makes the program run slightly slower.

Release builds are optimized executable files stored in the bin\release folder within your project. To customize the settings for your release build, you click the [ProjectName] Properties command on the Project menu, and then click the Compile tab, where you see a list of compilation options that looks like this:

Try creating a release build named MyLucky7.exe now.

Create an executable file

  1. On the Build menu, click the Build MyLucky7 command.

    The Build command creates a bin\release folder in which to store your project (if the folder doesn't already exist) and compiles the source code in your project. The result is an executable file named MyLucky7.exe. To save you time, Visual Studio often creates temporary executable files while you develop your application; however, it's always a good idea to recompile your application manually with the Build or Rebuild commands when you reach an important milestone.

    Try running this program outside the Visual Studio IDE now by using the Run command on the Start menu.

  2. On the Windows taskbar, click Start, and then click Run.

    The Run dialog box appears.

  3. Click Browse, and then navigate to the c:\vb05sbs\chap02\mylucky7\bin\release folder.

  4. Click the MyLucky7.exe application icon, click Open, and then click OK.

  5. The Lucky Seven program loads and runs in Windows.

  6. Click Spin a few times to verify the operation of the game, and then click End.

    TIP

    You can also run Windows applications, including compiled Visual Basic programs, by opening Windows Explorer and double-clicking the executable file. To create a shortcut icon for MyLucky7.exe on the Windows desktop, right-click the Windows desktop, point to New, and then click Shortcut. When you're prompted for the location of your application file, click Browse, and select the MyLucky7.exe executable file. Click the OK, Next, and Finish buttons. Windows places an icon on the desktop that you can double-click to run your program.

  7. On the File menu, click Exit to close Visual Studio and the MyLucky7 project.

    The Visual Studio development environment closes.

Deploying Your Application

Visual Studio helps you distribute your Visual Basic applications by providing several options for deployment—that is, for installing the application on one or more computer systems. Whereas Visual Basic 6 requires a sophisticated setup program that copies dynamic-link libraries (DLLs) and support files and registers the application with the operating system, Visual Studio 2005 applications are compiled as assemblies—deployment units consisting of one or more files necessary for the program to run. Assemblies contain four elements: Microsoft intermediate language (MSIL) code, metadata, a manifest, and supporting files and resources.

Assemblies are so comprehensive and self-describing that Visual Studio applications don't need to be formally registered with the operating system to run. This means that theoretically a Visual Basic 2005 application can be installed by simply copying the assembly for the program to a second computer that has the .NET Framework installed—a process called XCOPY installation, after the MS-DOS XCOPY command that copies a complete directory (folder) structure from one location to another. In practice, however, it isn't practical to deploy Visual Basic applications by using a copy procedure such as XCOPY (via the command prompt) or Windows Explorer. For commercial applications, an installation program with a graphical user interface is usually preferred, and it's often desirable to register the program with the operating system so that it can be uninstalled later by using Add/Remove Programs in Control Panel.

To manage the installation process, Visual Studio 2005 allows developers to add a setup or Windows Installer project to their solutions, which automatically creates a setup program for the application. This setup project can be customized to allow for different methods of installation, such as CD-ROMs or Web servers. Best of all, in Visual Studio 2005 you can utilize a technology called ClickOnce to create a Web-based installation service for desktop applications that users can access on their own with minimal interaction. Although the advanced options related to deployment and security go beyond the scope of this book, you can get started with these features at any time by using the Publish command on the Build menu, or by using the New Project command on the File menu to create a custom Windows Installer project. (Select the Setup And Deployment option under Other Project Types to see a list of setup templates and wizards.) The Properties command on the Project menu has a Publish tab that you can use to customize your application's setup settings.

Категории