Monday, March 13, 2017

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/Debugbin/Release/.. , and  publish/Application Files/[Program and Version], as well as being including in online ClickOnce deployments.
Source : https://cerebrilaevi.wordpress.com/2010/06/10/including-external-files-in-a-c-clickonce-deployment/

No comments:

Post a Comment