22 June 2007

Deploying files with an Install project

Microsoft Visual Studio Pro provides a suite of tools for deploying files and creating a folder structure at install. At this point, I am not an expert at the deployment (see other deployment postings), but following is how to deploy files:

1. Right-click on the Install/Deployment package
2. Choose View > File System
3. Add files and folders. They will be added to the install structure defined in the deployment package.

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.

Regular Expressions and Like Statement

There is a new requirement for this application to be able to parse numbers embedded in file names. One issue is that C# DataTables do not allow for complex, regular expression searches in fields. That means that I will have to create on the fly regular expressions, query my local files database and then run a post process on the remaining records to see if more than one file comes up.

The query process will be as follows:

1. When loading hooks into the table, replace [snam] with the SNAM
2. Create a boolean value in the table to indicate if the hook has a [n] wildcard in it
3. Query the files table with the first [n] in the hook as the */% wildcard
4. Pass the records to a function with the hook. The function returns the number of records found.
5. Build a regular expression based on the string. Replace '[n]' with '[0-9]+'
6. Cycle through the array. If a match is found, increment the match.
7. Return the array back to the calling function for processing.