Deployment Tools Foundation
Working with Install Packages
Development Guide > Install Packages

### Updating files in a product layout

The InstallPackage class makes it easy to work with files and cabinets in the context of a compressed or uncompressed product layout.

This hypothetical example takes an IDictionary 'files' which maps file keys to file paths. Each file is to be updated in the package layout; cabinets are even recompressed if necessary to include the new files.

        using (InstallPackage pkg = new InstallPackage("d:\builds\product.msi",
            DatabaseOpenMode.Transact))
        {
            pkg.WorkingDirectory = Path.Combine(Path.GetTempFolder(), "pkgtmp");
            foreach (string fileKey in files.Keys)
            {
                string sourceFilePath = files[fileKey];
                string destFilePath = pkg.Files[fileKey].SourcePath;
                destFilePath = Path.Combine(pkg.WorkingDirectory, destFilePath);
                File.Copy(sourceFilePath, destFilePath, true);
            }
            pkg.UpdateFiles(new ArrayList(files.Keys));
            pkg.Commit();
            Directory.Delete(pkg.WorkingDirectory, true);
        }

1. Create a new InstallPackage instance referring to the location of the .msi. This is actually just a specialized subclass of a Database.

2. Set the WorkingDirectory. This is the root directory where the package expects to find the new source files.

3. Copy each file to its proper location in the working directory. The InstallPackage.Files property is used to look up the relative source path of each file.

4. Call InstallPackage.UpdateFiles with the list of file keys. This will re-compress and package the files if necessary, and also update the following data: File.FileSize, File.Version, File.Language, MsiFileHash.HashPart*.

5. Commit the database changes and cleanup the working directory.

See also:

- WiFile Sample Tool - a more complete tool that expands on the above example.
- InstallPackage Class