namespace WixBuilder
{
    using System;
    using System.IO;

    /// <summary>
    /// A program.
    /// </summary>
    internal class Program
    {

        #region Fields

        private static String exe = @"YourApplication.exe";
        private static String src = @"YourProjectDir\bin\Debug";

        #endregion Fields

        #region Methods

        private static void Main(string[] args)
        {
            using (WixDefinition wd = new WixDefinition(src, exe))
            {
                // Make sure CompanyName does not contain strange characters as it's used for directory name etc.
                wd.CompanyName = "Your Company";
                wd.SkipLicence = true;
                wd.Supress = new WixIceCodes[] { WixIceCodes.ICE64, WixIceCodes.ICE69, WixIceCodes.ICE91 };

                ///////////////////////////
                // Product.wxs.
                ///////////////////////////

                wd.BuildProduct();
                {
                    wd.AddSimpleUI();
                }
                wd.SaveProduct();

                ///////////////////////////
                // Fragment.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);

                    //! 3) Should end up in ProgramFiles\[ProductName].
                    String chmId = wd.AddFile(WixDefinition.InstallLocation, "YourApp.chm", true);

                    //! 4) Should end up in MyDocuments\[ProductName].
                    wd.AddFiles(WixDefinition.AppDocFolder, "*.docx", SearchOption.AllDirectories, true);

                    //! 5) Should end up in %appdata%\[ProductName]\script.
                    wd.AddFiles(WixDefinition.AppDataLocation, "*.ini", SearchOption.AllDirectories, false);

                    //! 6) Shortcut Should end up in UserMenu\[ProductName].
                    String exeComp1 = wd.AddComponent(WixDefinition.ApplicationProgramsFolder);
                    wd.AddShortCut(
                        WixDefinition.ApplicationProgramsFolder,
                        exeComp1,
                        "[#" + exeId + "]",
                         WixDefinition.InstallLocation,
                        String.Empty,
                        String.Empty,
                        wd.ProductName);

                    //! 7) Shortcut Should end up on Desktop.
                    String exeComp2 = wd.AddComponent(WixDefinition.DesktopFolder);
                    wd.AddShortCut(
                        WixDefinition.DesktopFolder,
                        exeComp2,
                        "[#" + exeId + "]",
                         WixDefinition.InstallLocation,
                        String.Empty,
                        String.Empty,
                        wd.ProductName);

                    //! 8) Shortcut Should end up in UserMenu\[ProductName].
                    String chmComp = wd.AddComponent(WixDefinition.ApplicationProgramsFolder);
                    wd.AddShortCut(
                        WixDefinition.ApplicationProgramsFolder,
                        chmComp,
                        "[#" + chmId + "]",
                         WixDefinition.InstallLocation,
                        String.Empty,
                        String.Empty,
                        String.Format("{0} Help", wd.ProductName));

                    //! 9) Shortcut Should end up in UserMenu\[ProductName].
                    String uninstComp = wd.AddComponent(WixDefinition.ApplicationProgramsFolder);
                    wd.AddShortCut(
                        WixDefinition.ApplicationProgramsFolder,
                        uninstComp,
                        "[System64Folder]msiexec.exe",
                         WixDefinition.InstallLocation,
                        String.Empty,
                        "/x [ProductCode]",
                        String.Format("Uninstall {0}", wd.ProductName));
                }
                wd.SaveFragment();

                ///////////////////////////
                // Compile and Build msi.
                ///////////////////////////

                wd.PrintOmittedFiles();

                if (!String.IsNullOrEmpty(wd.WiXDir) && Directory.Exists(wd.WiXDir))
                {
                    if (wd.Compile())
                    {
                        if (wd.Link())
                        {
                            //wd.Test();
                            //wd.View();
                        }
                    }
                }
            }

            Console.WriteLine("");
            Console.Write("Press any key to exit");
            Console.ReadKey();
        }

        #endregion Methods

    }
}

Last edited Aug 21, 2014 at 3:01 PM by wvd_vegt, version 1