Including external files in a C# ClickOnce deployment

The first version of my Battleships program is done. I’ll be releasing it into the wild today or tomorrow. One hurdle I stumbled over was on how to include XML files as external files in the ClickOnce deployment. My normally strong GoogleFu is weak on matters of C#; I’m not sure if that’s due to a paucity of quality information, or personal lapses.

I designed the Battleships puzzle files to be easy to upgrade, so someone who enjoys using the program can create their own puzzle files, perhaps from a magazine source (I’m not sure if Kappa [Games] is the sole publisher of these puzzles, and at any rate they have been running for them for a while and I’m not going through my entire back catalog). Puzzle files are in XML format, with hopefully superficial tags and structure.

As part of the deployment, I’m including two puzzle files, containing the puzzles from the May 2010 and July 2010 issues of Games Magazine. It turns out there are several settings that need to be changed from the default in order to accomplish this.

External Resource Step 1

The resources tab

First, and perhaps most obviously, the files need to be added as a resource. Do this by going to Project>[Program] Properties…. Select the Resources tab along the left, then Select Files from the first drop down, click Add Resource, and select the files you want (note that the default is to only list text files; for other types of files, change the option). Select the files that you want; if your resources are in a subdirectory (as mine are), VC# will use a relative path and maintain the subdirectory structure.

Added resources

Resources in the Solution Explorer

The resources are now available to the solution, but they won’t be available for either debugging or deployment; they’d have to be manually copied. The next step is to change the properties of each file. Note that you can change the properties of multiple files by ctrl-selecting them. Right-click and select Properties (or press Alt-Enter), then set Build Action to Content and Copy to Output Directory to Copy Always. This will copy the files to the debugging subdirectory at compile time, but they still won’t be available in a ClickOnce deployment.

Deploying external resources

Including external resources in the deployment

Finally, return to the project properties window and select the Publish tab. Select Application Files…. Change the Publish Status to Include. Now, when you publish, the resource files should be included in three places: bin/Debug, bin/Release/.. , and  publish/Application Files/[Program and Version], as well as being including in online ClickOnce deployments.

Advertisements
This entry was posted in Battleships, C#, Grid-based and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s