Building MSI with Wix# – Step by step tutorial

WixSharp Installation

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` command. 

Now you can build your MSIs. As an example let’s create a simple MSI for installing MyApp.exe and readme.txt files.

Target destination:  
    [Program Files]\My Company\My Product

Files to deploy:

Step 1

In the <root> folder create setup.cs file (build script) containing the following code:

using System;
using WixSharp;

class Script
static public void Main()
var project = new Project("MyProduct",
new Dir(@"%ProgramFiles%\My Company\My Product",
new File(@"Files\Docs\readme.txt"),
new File(@"Files\Bin\MyApp.exe")));

project.GUID = new Guid("6f330b47-2577-43ad-9095-1861ba25889b");



Step 2

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++
    • Enable CS-Script plugin in Notepad++
    • Place WixSharp.dll from WixSharp package in the <root> directory.
      If you already have WiX toolset installed then you can just instruct Notepad++ to download the dll from the NuGet server by placing //css_nuget directive at the top of your script:
      //css_nuget WixSharp.bin;
      //css_ref System.Core.dll;
      using System;
      using WixSharp;
    • Load setup.cs in Notepad++ and press F5.
  • 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

Last edited Apr 18, 2016 at 2:29 AM by oleg_s, version 5