16

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 reference fragments where I want a bulk copy of its content??
For example I have a fragment which tests if .net framework is installed and I want to include that fragment in my main wix file in the project tag...
Here's the fragment located in my wixlib that I want to include in several wix project:

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

Thanks!!

Steph Ragazzi
  • 381
  • 1
  • 4
  • 15

2 Answers2

20

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!

Alex
  • 583
  • 5
  • 18
  • I'm coming in completely new to this, but it seems to me that when you pull multiple .wxs files in, your adding them to kind of a global namespace. Ergo, it seems like to use them, you'd have to explicitly set them. – ruckc Oct 09 '17 at 02:24
  • `FragmentRef` was a nice feature but it is gone on Wix3 and Wix4, The way going over `Component` and `ComponentRef` is the way to "link" a Fragment to another content – KargWare Feb 20 '20 at 06:52
17

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...

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
  • thanks a lot Yan! I have added the ComponentGroup to my fragment and the ComponentGroupRef to my feature but I don't know why, I get an error:Unresolved reference to symbol WixComponentGroup:CMPGRP_Fake in section Product:... I have referenced my wixlib and other elements that I reference with PropertyRef are OK... Any idea? – Steph Ragazzi Nov 02 '11 at 11:29
  • Hmm... have you re-built the wixlib? – Yan Sklyarenko Nov 02 '11 at 12:26
  • yes..No errors...but when I uncomment the ComponentGroupRef in the feature I get the error. – Steph Ragazzi Nov 02 '11 at 12:44
  • Make sure the names in ComponentGroup and ComponentGroupRef Id attributes are the same... – Yan Sklyarenko Nov 02 '11 at 12:55
  • I've already checked and the Id are the same... I must have missed something but what...Thanks again for your help – Steph Ragazzi Nov 02 '11 at 13:01
  • Hmm, I ran out of ideas, sorry. I tested this on a simple Product.wxs + Fragment, which is not in wixlib. Check that old obj files aren't picked up during the build. Just clean build temp files and run a clean build... Hope you'll eventually find what is wrong – Yan Sklyarenko Nov 02 '11 at 13:07
  • it's OK now. At the beginning, I have created wxi instead of wxs. Then I have renamed wxi to wxs but the project file was wrong, still considering my wxs as a wxi... – Steph Ragazzi Nov 02 '11 at 14:42