Wix: Creating multiple associations for single fil

2019-08-03 20:20发布

问题:

I have a Wix based installer that installs two executables. I want to associate my own custom file type to both executables

<Component Id="A.exe" Guid="{GUID}">
    <File Id="A.exe" Name="A.exe" Source="../A.exe" KeyPath="yes" Checksum="yes"/>
    <ProgId Id="cfgfilerun" Description="Config file for A" Advertise="no" >
        <Extension Id="cfg" ContentType="application/text" Advertise="no" >
            <Verb Id="Run" Command="Run" TargetFile="A.exe" Argument='"%1"' />
        </Extension>
    </ProgId>
</Component>

then later

<Component Id="B.exe" Guid="{GUID}">
    <File Id="B.exe" Name="B.exe" Source="../B.exe" KeyPath="yes" Checksum="yes"/>
    <ProgId Id="cfgfileopen" Description="Config file" Advertise="no" >
        <Extension Id="cfg" ContentType="application/text" Advertise="no" >
            <Verb Id="Open" Command="Open" TargetFile="B.exe" Argument='"%1"' />
        </Extension>
    </ProgId>
</Component>

does not work. How to fix? Behavior is that only one of the extensions appears and works, the one for B. If I comment out B's ProgId, then I get the one for A.

回答1:

Fixed it by putting both files in the same component:

<Component Id="A.exe" Guid="{GUID}">
    <File Id="A.exe" Name="A.exe" Source="../A.exe" KeyPath="yes" Checksum="yes"/>
    <File Id="B.exe" Name="B.exe" Source="../B.exe" Checksum="yes"/>
    <ProgId Id="cfgfilerun" Description="Config file for A" Advertise="no" >
        <Extension Id="cfg" ContentType="application/text" Advertise="no" >
            <Verb Id="Run" Command="Run" TargetFile="A.exe" Argument='"%1"' />
            <Verb Id="Open" Command="Open" TargetFile="B.exe" Argument='"%1"' />
        </Extension>
    </ProgId>
</Component>

I looked at the debug output from logging from msiexec, what it was doing before with the cfg file just looked broken. I think this is a bug in Wix that you need to have everything in the same component. Generally, I'm a little disappointed with Wix overall, but then again I haven't used any of the competition. Perhaps all Windows installers are a total morass.