22 June 2007

Deploying files with a ClickOnce Project

Deploying files with a ClickOnce Project

The switch to deploying a Windows Services has got me thinking about how to deploy files and settings with the application. So, today I have been exploring the various ways to deploy data files with C# projects. Following are the ways I have discovered:

--------------------------------------------------
Project Properties > Resources
Resources are files that can be compile directly into the executable. I would recommend this for XSD or XML files that will not be edited after deployment.

How to Reference:
[Namespace].Resources.Resource Name;

Pros: Easy to reference and deploy. In testing, XML files were rendered as strings and easily loaded into memory for easy parsing.
Cons: I do not believe that resources can be edited after deployment. They are compiled directly into the executable.
--------------------------------------------------
Project Properties > Settings
This looks like the best place to store editable data. These settings are deployed in the .config file stored in the application directory with the executable. The file is an XML file - change the appropriate setting. It looks like settings can be set to simple or complex types and can be changed programmatically at run time. They can also be changed at run time.

How to reference: [Namespace].Properties.Settings.Default[string id];

Pros: It is easy to change the settings once the application is deployed.
Cons: The format my take complex types, but I'm not sure if it is serialized in a human readable format. Strings are easily editable provided you can find the .config file on the hard drive.

--------------------------------------------------
Data Files
Data files are added directly to the project. They are deployed in their original state with each install.

How to reference: You need to check to see if the system is in a deployed state. If yes, the look in the ApplicationDeployment.CurrentDeployment.DataDirecrory. From an editing perspective, the files can be edited at runtime.

Pros: The file makes the transition to the deployed computer completely intact. Coding for the local location is not difficult.
Cons: The install directory for the data file is complex and contains a guid. If there is more than one version of the application installed on the machine, it may be difficult, if not impossible, to find and update the correct file. The coding for checking the deployed stated is a little obtuse, but that could be solved with a quick object.