问题
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!!
回答1:
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...
回答2:
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!
来源:https://stackoverflow.com/questions/7978066/how-to-include-fragments-in-wix