This project is read-only.
Authoring MSI


Authoring MSI with Wix# consist of three distinctive steps: declaring an instance of the WixSharp.Project, defining the compilation action with WixSharp.Compiler and executing the build script.

Defining a Wix# Project
<Wix# Samples>\CodingStyles

Instantiating the Wix# project is as simple as instantiating any C# class. And as with any trivial class declaration it can done in various ways/styles:

Traditional (plain C# routine)

var docFile = new File(@"Files\Docs\Manual.txt");
var exeFile = new File(@"Files\Bin\MyApp.exe");
var dir = new Dir(@"%ProgramFiles%\My Company\My Product");

dir.Files = new[] { docFile, exeFile };

var project = new Project();
project.Dirs = new[] { dir };
project.Name = "MyProduct";

Class initializers

var project =
new Project()
Name = "MyProduct",
GUID = new Guid("6f330b47-2577-43ad-9095-1861ba25889b"),
Dirs = new[]
new Dir(@"%ProgramFiles%\My Company\My Product")
Files = new []
new File(@"Files\Docs\Manual.txt"),
new File(@"Files\Bin\MyApp.exe")

XDocument style constructors

var project =
new Project("MyProduct",
new Dir(@"%ProgramFiles%\My Company\My Product",
new File(@"Files\Docs\Manual.txt"),
new File(@"Files\Bin\MyApp.exe")));

XDocument style deserves special attention. WixSharp Project, Dir and File constructors are extremely similar to the XDocument/XElement constructors accepting an open end lists parameters of the generic base type.

System.Xml.Linq.XElement(XName name, params Object[])
WixSharp.File(string name, params WixEntity[])

This style of instantiation has proven to be effective and easy to read for the definition of the XML structure (LINQ for XML). Therefore, the XDocument style has been chosen as the default instantiation style for all Wix# samples.

A part from being convenient using constructors has another strong advantage. It allows automatic generation of the directory structure via splitting the name (path) constructor argument. Thus passing "%ProgramFiles%\My Company\My Product" as the constructor argument triggers creation of the nested directories 'My Company' and "My Product". And the next File argument is automatically pushed to the bottom-most subdirectory "My Product".

Using constructors also helps avoiding potential id clashes associated with the manual id assignments. See "Explicit IDs" sample for details.

Last edited Apr 15, 2015 at 8:39 AM by oleg_s, version 1