Building MSI with Wix# – Step by step tutorial
Building MSI with Wix# is quite simple. But first you need prepare your building environment:
- Download (and extract) Wix# binaries from the Downloads section. You may but don’t have to download WiX as Wix# package already contains compatible copy of WiX.
- Create environment variable WIXSHARP_WIXDIR pointing to the WiX ‘bin’ folder
- you can do it either manually. Normally the ‘bin’ path is “<WixSharp>\Wix_bin\bin”
- or you can just execute install.cmd from the Wix# package
You will need to ensure that WIXSHARP_WIXDIR was roperly creates as otherwise Wix# may not be able to find WiX compilers.
WiX Toolset installation
Wix# does require WiX binaries (compilers, linkers etc.). Wix# is capable of automatically finding WiX tools only ifWiX Toolset installed. In all other cases you need to set the environment variable WIXSHARP_WIXDIR or WixSharp.Compiler.WixLocation
to the valid path to the WiX binaries.
WiX binaries can be brought to the build environment by either installing WiX Toolset, downloading Wix# suite or by adding WixSharp.wix.bin NuGet package to your project. For bringing WiX Tools from NuGet use `Install-Package WixSharp.wix.bin`
Now you can build your MSIs. As an example let’s create a simple MSI for installing MyApp.exe and readme.txt files.
[Program Files]\My Company\My Product
Files to deploy:
In the <root> folder create setup.cs file (build script) containing the following code:
static public void Main()
var project = new Project("MyProduct",
new Dir(@"%ProgramFiles%\My Company\My Product",
project.GUID = new Guid("6f330b47-2577-43ad-9095-1861ba25889b");
Now you need to execute setup.cs script. It can be bone using one of the following techniques:
- Building with CS-Script
- Place both cscs.exe and WixSharp.dll from WixSharp package in the <root> directory.
- Run “cscs.exe setup.cs” from command prompt or batch file
- Building with Notepad++
- Building with Visual Studio
- In the <root> directory create C# Console Application project. Ensure project file and Program.cs are located in the <root> directory.
- Use package manager to install NuGet package: "Install-Package WixSharp"
- In Visual Studio project replace auto-generated Program.cs with setup.cs file.
- In the project properties ensure ‘Target framework’ is set to v3.5
Also set ‘Post-build event command’ as follows:
- Build/Rebuild project