Вопрос

I have an MSI file created with WiX, that intalls my executables and copies a configuration file, that placed near the MSI file. I can change configuration file before installation and the changed version will be copied to installation folder.

<Component Id="ProductComponent" 
           Guid="714DCBE1-F792-401E-9DDC-67BC1853BE14">
    ....
    <File Source="Chiffa.exe.config" 
          Compressed='no'/>
</Component>

That is what I want and I'm happy, but not satisfied, because I need to install some other packages along with this MSI file. So I created a bundle project with WiX and placed all my lovely MSI packages to its chain:

<Chain>
    .....
    <MsiPackage Compressed="yes"
                SourceFile="$(var.ChiffaSetup.TargetPath)"
                Vital="yes"
                Visible="no">
        <Payload SourceFile="Chiffa.exe.config"
                 Compressed="no"/>
    </MsiPackage>
</Chain>

Everything is works fine except one little thing. I can't change the configuration file since bundle checks the consistency of an MSI package and fails with "the hash code" thing.

Это было полезно?

Решение 2

I think the solution is to exclude the configuration file from the MSI package and use custom action to copy file (or create default if one does not exists). And, of course, the action can makes any checks of the file if it's nessesary.

But you have to add code to manage the configuration file during uninstallation process and so on. it's another custom action.

Something like that:

[CustomAction]
public static ActionResult CopyBootstraperConfig(Session session)
{
    try
    {
        const string configFile = "Chiffa.exe.config";

        var customConfig = Path.Combine(Path.GetDirectoryName(session["OriginalDatabase"]), configFile);
        var targetConfig = Path.Combine(session.GetTargetPath("INSTALLLOCATION"), configFile);
        if (File.Exists(customConfig))
            File.Copy(customConfig, targetConfig);
        try
        {
           //do file checks
        }
        catch (Exception e)
        {
            File.Delete(targetConfig);
            throw;
        }
    }
    catch (Exception e)
    {
        return ActionResult.Failure;
    }
    return ActionResult.Success;
}

Другие советы

The "hash code thing" is a very important feature since it detects incomplete or corrupt downloads. If you need arbitrary changes to the config file then you'll just have to rebuild the bundle for each change.

But, if you can define an algorithm for the changes then you can change the config file as it is installed with XmlConfig elements in your Setup project or by using a custom action of your own. The data for the changes could be defined completely within the algorithm or passed via various mechanisms: Windows Installer properties set via the UI or command-line arguments. If set via command-line argument, they can be passed from the bundle, which could get them from a custom BootstrapperApplication UI or from its command-line.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top