Getting Started

See also the Full Example.

Create WixDefinition object (IDisposable is supported).

   using (WixDefinition wd = new WixDefinition(src, exe))
   {
      // Code 
   }


where src is the output directory if the project you want to create an installer for and exe is the filename of the main executable.

Note: Path.Combine(src, exe) must be equal to the full path of the main executable.

Set some properties or correct some values if necessary:

    // Make sure CompanyName does not contain strange characters.
    wd.CompanyName = "My Company";
    wd.SkipLicence = true;


Note: Some values like CompanyName, ProductName and ProductVersion are extracted from the main executable.

Create the product.wxs

    wd.BuildProduct();

    // Add Simple GUI.
    wd.AddSimpleUI();

    wd.SaveProduct();


Here we first create a skeleton product.wxsfile, add the UI to it and finally save this file.

Create the fragmant.wxs

    wd.BuildFragment();

    //! 1) Should end up in ProgramFiles\[ProductName].
    String exeId = wd.AddFile(WixDefinition.InstallLocation, wd.MainExecutable, true, true);

    //! 2) Should end up in ProgramFiles\[ProductName].
    wd.AddFiles(WixDefinition.InstallLocation, "*.dll", SearchOption.AllDirectories, true);


Here we add the main executable and all assembly dll's found in the src directory (and below).

Note: A file can be added only once with a wildcard so it is possible to have multiple AddFiles call handling assemblies.

Add an icon to the main executable to the user's menu

    String exeComp1 = wd.AddComponent(WixDefinition.ApplicationProgramsFolder);
    
    wd.AddShortCut(
        WixDefinition.ApplicationProgramsFolder,
        exeComp1,
        "[#" + exeId + "]",
        WixDefinition.InstallLocation,
        String.Empty,
        String.Empty,
        "Your Program's Name");

Finally save the fragment.wxs and compile/link/test the installer

    wd.SaveFragment();

    wd.PrintOmittedFiles();

    if (wd.Compile() && wd.Link()) {
        wd.Test();
        wd.View();
    }


Note: Test will run the newly created msi installer in logging more and view will open/show the logfile created.

Last edited Aug 21, 2014 at 3:03 PM by wvd_vegt, version 13