How to include fragments in Wix?

后端 未结 2 1791
无人共我
无人共我 2021-01-04 04:46

I have created a wixlib to share fragments in some wix projects.
I can reference fragments which have Property in my main wix file with a PropertyRef, but how can I refe

相关标签:
2条回答
  • 2021-01-04 05:06

    Back in the old days of wix 2 we used to have FragmentRef elements. It was very easy to include any fragment in your Product section and it was very easy for anyone reading the xml to figure out what was being done.

    <FragmentRef Id="CustomActionFrag" />
    <FragmentRef Id="PropertiesFrag" />
    

    Now in wix 3 they have eliminated the FragmentRef element. Not sure why. I find it very anoying, because in my Product element I have to add several references to "something defined in my fragments"

    <CustomActionRef Id="caDoSomething"/>
    <PropertyRef Id="PropCryptic"/>
    

    If I don't do that the fragment is completely ignored and does not make its way into the final MSI.

    That's very cryptic for anyone reading the xml. Give my FragmentRef's back!

    0 讨论(0)
  • 2021-01-04 05:09

    That's an interesting question! The tutorial says that anything that can be delegated into a fragment has its variant tag: FeatureRef for Feature, PropertyRef for Property, etc. However, the contents of the fragment in your question doesn't issue any errors and the project builds fine.

    I don't know whether it is intentional of not, the Fragment element itself doesn't have a ref brother FragmentRef. For some reason the Fragment element has an optional Id attribute, but it is indicated to be set by advanced users to tag sections. I don't know what it means...

    But, it seems you can cheat here. :-) Add a fake ComponentGroup element to your Fragment, which doesn't contain any real Components:

      <Fragment>
        <PropertyRef Id="NETFRAMEWORK35" />
        <Condition Message="framework 3.5 is not installed">
          <![CDATA[Installed OR NETFRAMEWORK35]]>
        </Condition>
        <ComponentGroup Id="Fake" />
      </Fragment>
    

    Now, you can reference that ComponentGroup in your main Product.wxs, and the contents of the entire Fragment will be included as promised by the manual:

       <Feature Id="ProductFeature" Title="My product feature" Level="1">
          <ComponentRef Id="ProductComponent" />
          <ComponentGroupRef Id="Fake"/>
       </Feature>
    

    As long as ComponentGroup doesn't has any meaning to the MSI itself, it doesn't bring garbage to the MSI package. But it pollutes the source code, of course...

    0 讨论(0)
提交回复
热议问题