Using Wix to generate an MSI
Asked Answered
B

2

6

I am using Wix 3.8 to create an MSI installer for a Visual Studio project I have created. I followed this simple tutorial but even with this simply Wix project I am getting errors. Here is My

I have added my VS2012 project as a reference to my Wix Installer.

Here is my Product.ws file:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'
   xmlns:iis='http://schemas.microsoft.com/wix/IIsExtension'>
    <Product Id="*" Name="MyProjectInstaller2" Language="1033" Version="2.0.0.0" Manufacturer="Company" UpgradeCode="7f5b63be-bdad-4cc9-b4df-b3f1648c0539">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />

        <Feature Id="ProductFeature" Title="MyProjectInstaller2" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="MyProjectInstaller2" />
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
            <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
            <!-- <Component Id="ProductComponent"> -->
        <File Source="$(var.MyProject.TargetPath)" />
            <!-- </Component> -->
        </ComponentGroup>
    </Fragment>
</Wix>

When I compile this, I get the following error:

The ComponentGroup element contains an unexpected child element 'File'.

I have searched the bowels of the internet for a solution to this very basic problem. Why is VS2012 not recognising the element?

Berthoud answered 22/9, 2014 at 15:3 Comment(3)
What happens if you uncomment the Component element?Stephenstephenie
Try the Wix Schema Reference: ComponentGroup Element or File Element.Lithia
I did what John did and ran into the same issue. Sure the fix is easy enough, but the point is this tutorial is wrong (this is probably the go-to tutorial for anyone using WiX in VS for the first time!). And apparently, it has been since at least 2014 when this question was asked. Using latest v3.11 / VS2017 tools.Qualified
C
6

You should follow next hierarchy: ComponentGroup -> Component -> File and etc. In your example i suggest to you to put File element into separated component and then add this component into ComponentGroup. Try something like this:

<Component Directory="YOUR-DIRECTORY" Guid="your-guid" Id="SomeComponent">
    <File Source="$(var.MyProject.TargetPath)"/>
</Component>
<ComponentGroup Directory="INSTALLFOLDER" Id="ProductComponents">
    <ComponentRef Id="SomeComponent"/>
</ComponentGroup>
Coz answered 22/9, 2014 at 16:25 Comment(0)
B
1

Read the TODO comment right above your <File Source> You need to remove the comments around <Component Id="ProductComponent"> and </Component>.

Basidiospore answered 15/2, 2021 at 21:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.