WiX installer does not work on vs 2012

2019-05-11 11:49发布

问题:

I want to create a setup installer for my application. I have downloaded WiX 3.6 and installed it on vs 2012.

  1. Create simple winform application
  2. Add WiX setup project to my solution
  3. Right click on reference and add my winform application to setup's reference
  4. I build solution and go to debug directory in setup project and run SetupProject1.exe.msi it does not work and closes the installer dialog without any error.

Go back to setup project

  1. Right click on setup project and select properties
  2. On installer tab > output type, change it to executablefile.exe
  3. Build it and go to debug and run SetupProject1.exe - still does not work

What is wrong? This is my setup project product.wxs

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="SetupProject1" Language="1033" Version="1.0.0.0" Manufacturer="Natiloos" UpgradeCode="cfc2f4dd-2da5-49e2-9099-96968d75aaa4">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

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

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

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="SetupProject1" />
        </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"> -->

        <!-- </Component> -->
    </ComponentGroup>
</Fragment>

How can I get the installer to build correctly?

回答1:

The problem is your installer is not installing anything. Adding your project as a reference to the installer does not mean the installer will include your projects output. In your setup project you have:

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

    <!-- </Component> -->
  </ComponentGroup>
</Fragment>

You need to add the files...i.e. uncomment the <Component></Component> tags and add your files manually. It's good to have one <Component> tag per file.

Example:

 <Component Id="MyProgram.exe" Guid="PUT-GUID-HERE">
      <File Id="MyProgram.exe" KeyPath="yes" Source="Path_To_Output_Folder\MyProgram.exe" />
 </Component>


回答2:

WiX projects of the type that you are describing produce MSI files, with the .msi extension. These installers are not run directly, rather then are run using msiexec.exe. Windows explorer does this for you by default when you double click on them, however you can explicitly call msiexec using a command like the following

msiexec MyInstaller.msi

Note that MSI files are completely different from executables - changing the output name of your setup produce to have an .exe extension, or renaming the file to have an .exe extension won't work.

If you want to produce an .exe based installer then what you need is a bootstrapper. WiX has one called Burn, however if I were you I would worry about making an MSI that works first and then worry about creating an executable bootstrapper.