Coding a Euchre Game, Part 9: Into the Wild Blue Yonder (Matt Gertz)
Coding a Euchre Game, Part 9: Into the Wild Blue Yonder
So, here we are at the end of this series, which I hope you’ve found interesting. In this final post, I’m going to talk about deployment – getting your code shipped to another person. Oh, and the final code (including the deployment project) is included at the bottom of this post.
It can be a lot of fun to code & play your own card game, but at some point, you’re going to want to share it with friends or sell it to customers. Visual Studio gives you two options for this: Click-Once deployment and Setup projects. I’ve opted for setup projects for the Euchre game, since I don’t have a web server for my friends and family to download the game from, but it’s worth discussing Click Once as well.
Click Once deployment is very simple to use – all you need is a location to which to deploy the application that others can get to as well. Click Once doesn’t require creating a new project; you can run everything from the the application itself.
To start a basic Click Once operation, right-click on the project and choose “Publish…” If you wanted to, you could then just click “Finish” in the resulting wizard and deploy the application to the default location (hence the name “Click Once”); however, you’re likely to want to deploy it elsewhere. Type in the address of the site you wish to deploy to (http, ftp, file share, and disk path are all supported) and click “Next.” On the next page, decide whether or not you want the application to be usable all the time, or only when the user is connected to the internet. (The default is that the application is always usable.) Click “Next” and review the information, clicking “Finish” if everything is correct. The application will deploy (this can take a while, depending on where you’re deploying it to, the connection speed, etc.), and then you’ll be presented with a web page which has the download instructions on it. This is the page your friends/family/customers will navigate to in order to download the application; clicking the install button on this page will cause the app to download and install. Best of all, if you update your app and republish it, your users will automatically get the updates they next time they start up the application. (That’s a default behavior that you can change.)
If you want a little more control over Click Once, you can bring up the project properties (right-click the project, choose “Properties”) and click on the “Publish” tab. Here you can specify the target publishing directory and offline behavior as before, but you can also specify an installtion URL (if you don’t want to use the default page that gets created and a version number, and (more importantly) you can also specify prerequisites. Click the button labelled “Prerequisites.” Notice in the resulting dialog that .NET 2.0 is already selected, and that the default setting is for the user to download .NET 2.0 from the same place as your application (if they don’t already have it installed) – you’ve got a copy of the redistributable .NET package, and that gets deployed along with your application.
Of course, if you want speech to work, you also need to make sure that the speech redist package gets installed. You will note that it is *not* listed as one of the prerequisites. Click Once looks for prerequisites in C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages – there are directories there which contain each of the redistributable packages. I’m not going to go into this overmuch here, but to add a prerequisite to the list, you need to create an appropriately-named directory here, copy over the (expanded) Speech SDK redistribution files (which we downloaded in on of the previous posts), and add a product.xml file in the directory. The product.xml file is slightly arcane, so if you *really* want to do this, I suggest checking out the other product.XML files in there. I may cover this topic in more detail later (I’ll be totally honest; I’ve never added a prerequisite myself), but in the meantime I’ll press on to another mechanism for deployment which will support deploying the Speech redist package without much fuss: setup projects.
Setup projects are a great way to create installers for your application, particularly if you’re going to be distributing your application on CD. Setup projects use Windows Installer technology, and so will be installable by anyone running any recent version of Windows. Here’s what you need to do:
(1) Create a setup project. Click the “File” menu and choose “Add”à “New Project.” In the resulting dialog, expand the “Other Project Types” node, select the “Setup and Deployment” chil node, and choose “Setup Project” in the listview. Give it the name “VBEuchre Installer.”
(2) Add the outputs of the Euchre game to the setup project. Right-click on the installer project and choose “Add”à “Project Output.” Make sure that the Euchre game project is selected in the top drop-down and that “Primary Output” is selected in the list box. Press OK. The primary outputs of the Euchre game will be added to the setup project – every time the setup project builds, it will ask the Euchre project for its primary outputs (that is, the VBEUCHRE.EXE file that it builds). This is better than adding the EXE file directly to the setup project, because using the “project output” option will also force the Euchre app to make sure that it is fully built.
(3) Add the speech redist. The setup project will already have detected that the Euchre game requires the speech DLLs, but we want to make sure that the proper installation is followed. We’ll use merge modules for this – they are binaries which contain installation information for a feature or set of features. Too add them, right-click the installer project and choose “Add”à “Merge Module.” In the file dialog that follows, navigate to the speech directory and select the following MSM files there: Sp5, Sp5intl, Sp5TTInt, Sp5TTIntXP, SpCommon. By adding these merge modules, your installer will set up the Speech redist on the target machine, including all of the spiffy voices. Note that the .NET dependency will be handled automatically.
(4) Add any “decorations” you want. Want to add a shortcut on the user’s desktop during the install? No problem! Right-click the installer project and choose “View”à”File System.” This will bring up a file system editor which gives allows you to specify where things will go on the target machine. Select “Application Folder” (on the user’s machine, this will typically translate to “C:\Program files\VBEuchre”)and in the right-hand pane, right-click on the “Primary Output of VBEuchre (Active)” and choose “Create Shortcut to Primary Output of VBEuchre (Active).” Drag the resulting shortcut to “User’s Desktop.” Repeat this to create another shortcut, but drag it to “User’s Programs Menu” this time. That’s pretty much it – when installed, there will be a shortcut on the user’s desktop and in their programs menu.
That’s all you have to do (although there are certainly other things that you can do using setup projects as well). Build the setup project, and you’ll find the results in the Release directory for the installer project. Burn ‘em to CD, and hand it out to your friends, family, or customers.
The entire solution is appended to this post. Important note: The setup project expects the Speech MSMs to be in its directory, but I have not included them in this zip file — they are too big to attach (11 MB total)! If you want to try out the setup project, you will need to download the Speech SDK (as mentioned in a previous post) and drag the 5 relevant MSMs into the installer’s project directory before the setup project will load correctly. (The actual Euchre project should open fine regardless.) I’ve also included all 44 pages of this blog series in a word document in the ZIP file in case you want to easily refer back to it.
Let me know if you have any problems with the game! That was a lot of typing for me, so I’m going to give my wrists a rest for about a week, and then I’ll return with an article on how I used VB to defeat malware. Talk to you then!