Defines file to be installed.
Inheritance: WixEntity
示例#1
0
    static private WixSharp.File RenamedFile(string source, string name)
    {
        var file = new WixSharp.File(source);

        file.Attributes["Name"] = name;

        return(file);
    }
示例#2
0
    public static void Main(string[] args)
    {
        //var project = new Project("MyProduct",
        //    new Dir(@"%ProgramFiles%\My Company\My Product", new File(@"Files\Bin\MyApp.exe"),
        //    new Dir(@"docs\manual", new File(@"Files\Docs\Manual.txt"))));

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

        //Compiler.BuildMsi(project);

        //

           // var binDir = new WixSharp.Dir(@"bin");

        var binFile = new File(@"Files\Bin\MyApp.exe");
        var docFile = new File(@"Files\Docs\Manual.txt");

          var binFiles = new WixSharp.File[]
          {
             binFile
          };

          var docFiles = new WixSharp.File[]
          {
              docFile
          };

        var binDir = new WixSharp.Dir(@"bin", binFiles);
        var docDir = new WixSharp.Dir(@"doc", docFiles);

        var mainDir = new WixSharp.Dir(@"%ProgramFiles%\My Company\DigDes WixSharp",
             binDir,
             docDir );

        //
        Project project = new Project("DigDes WixSharp",  mainDir );

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

        Compiler.BuildMsi(project);
    }
        private static File[] GetApplicationFiles()
        {
            return(new DirectoryInfo($@"..\Geta.GuiApplication\bin\{Configuration}").GetFiles()
                   .Select(x =>
            {
                var file = new File(x.FullName);
                if (x.Name == AppFileName)
                {
                    file.Shortcuts = new[]
                    {
                        new FileShortcut(AppName)
                        {
                            Id = "StartMenuLink",
                            IconFile = IconPath
                        }
                    };
                }

                return file;
            }).ToArray());
        }
示例#4
0
    private Dir AddProgramFiles(string rootPath, Dir parentDir, MsiDirectory directory)
    {
        var path = rootPath + @"\" + directory.RelativePath;

        var newDir = new Dir()
        {
            Name = directory.Name
        };

        var fileLength  = parentDir.Files.Length;
        var newFileList = new File[fileLength + directory.MsiFiles.Count];

        parentDir.Files.CopyTo(newFileList, 0);

        var startIndex = parentDir.Files.Length;

        foreach (var file in directory.MsiFiles)
        {
            newFileList[startIndex] = new File(file.Path);
            startIndex++;
        }

        newDir.Files = newFileList;

        foreach (var subDir in directory.MsiDirectories)
        {
            AddProgramFiles(rootPath, newDir, subDir);
        }

        var length  = parentDir.Dirs.Length;
        var newList = new Dir[length + 1];

        parentDir.Dirs.CopyTo(newList, 0);
        newList[length] = newDir;
        parentDir.Dirs  = newList;

        return(newDir);
    }
        static void Main(string[] args)
        {
            var opts = CmdLineOptions.Parse(args);

            var config = BuildConfiguration.Read(
                Path.Combine(opts.ConfigDir, MagicStrings.Files.ConfigYaml));

            Directory.CreateDirectory(opts.PackageOutDir);

            var ap = new ArtifactPackage()
            {
                TargetName          = "lsbeat",
                CanonicalTargetName = "lsbeat",
                Architecture        = MagicStrings.Arch.x86,
                Version             = Environment.GetEnvironmentVariable("GITHUB_VERSION").Trim('v'),
            };

            Console.WriteLine(ap.ToString());

            var pc = config.GetProductConfig(ap.TargetName);

            var companyName    = "Mirero";
            var productSetName = MagicStrings.Beats.Name;
            var displayName    = companyName + " " + MagicStrings.Beats.Name + " " + ap.TargetName;
            var exeName        = ap.CanonicalTargetName + MagicStrings.Ext.DotExe;

            // Generate UUID v5 from product properties.
            // This UUID *must* be stable and unique between Beats.
            var upgradeCode = Uuid5.FromString(ap.CanonicalTargetName);

            var project = new Project(displayName)
            {
                InstallerVersion = 500,

                GUID = upgradeCode,

                Name = $"{displayName} {ap.SemVer} ({ap.Architecture})",

                Description = pc.Description,

                OutFileName = Path.Combine(opts.PackageOutDir, opts.ShortPackageName),
                Version     = new Version(ap.Version),

                Platform = ap.Is32Bit ? Platform.x86 : Platform.x64,

                InstallScope = InstallScope.perMachine,

                UI = WUI.WixUI_Minimal,

                // TODO: Custom images?
                BannerImage     = Path.Combine(opts.ResDir, MagicStrings.Files.TopBannerBmp),
                BackgroundImage = Path.Combine(opts.ResDir, MagicStrings.Files.LeftBannerBmp),

                MajorUpgrade = new MajorUpgrade
                {
                    AllowDowngrades          = false,
                    AllowSameVersionUpgrades = false,
                    DowngradeErrorMessage    = MagicStrings.Errors.NewerVersionInstalled,
                },
            };

            project.Include(WixExtension.UI);
            project.Include(WixExtension.Util);

            project.ControlPanelInfo = new ProductInfo
            {
                Contact      = companyName,
                Manufacturer = companyName,
                UrlInfoAbout = "https://www.mirero.co.kr",

                Comments = pc.Description + ". " + MagicStrings.Beats.Description,

                ProductIcon = Path.Combine(
                    opts.ResDir,
                    Path.GetFileNameWithoutExtension(exeName) + MagicStrings.Ext.DotIco),

                NoRepair = true,
            };


            var beatConfigPath = "[CommonAppDataFolder]" + Path.Combine(companyName, productSetName, ap.CanonicalTargetName);
            var beatDataPath   = Path.Combine(beatConfigPath, "data");
            var beatLogsPath   = Path.Combine(beatConfigPath, "logs");

            var textInfo           = new CultureInfo("en-US", false).TextInfo;
            var serviceDisplayName = $"{companyName} {textInfo.ToTitleCase(ap.TargetName)} {ap.SemVer}";

            WixSharp.File service = null;
            if (pc.IsWindowsService)
            {
                service = new WixSharp.File(Path.Combine(opts.PackageInDir, exeName));

                // TODO: CNDL1150 : ServiceConfig functionality is documented in the Windows Installer SDK to
                //                  "not [work] as expected." Consider replacing ServiceConfig with the
                //                  WixUtilExtension ServiceConfig element.

                service.ServiceInstaller = new ServiceInstaller
                {
                    Interactive = false,

                    Name        = ap.CanonicalTargetName,
                    DisplayName = serviceDisplayName,
                    Description = pc.Description,

                    DependsOn = new[]
                    {
                        new ServiceDependency(MagicStrings.Services.Tcpip),
                        new ServiceDependency(MagicStrings.Services.Dnscache),
                    },

                    Arguments =
                        " --path.home " + ("[INSTALLDIR]" + Path.Combine(ap.Version, ap.CanonicalTargetName)).Quote() +
                        " --path.config " + beatConfigPath.Quote() +
                        " --path.data " + beatDataPath.Quote() +
                        " --path.logs " + beatLogsPath.Quote() +
                        " -E logging.files.redirect_stderr=true",

                    DelayedAutoStart = false,
                    Start            = SvcStartType.auto,

                    StartOn  = SvcEvent.Install,
                    StopOn   = SvcEvent.InstallUninstall_Wait,
                    RemoveOn = SvcEvent.InstallUninstall_Wait,
                };
            }

            var packageContents = new List <WixEntity>
            {
                new DirFiles(Path.Combine(opts.PackageInDir, MagicStrings.Files.All), path =>
                {
                    var itm = path.ToLower();

                    bool exclude =

                        // configuration will go into mutable location
                        itm.EndsWith(MagicStrings.Ext.DotYml, StringComparison.OrdinalIgnoreCase) ||

                        // we install/remove service ourselves
                        itm.EndsWith(MagicStrings.Ext.DotPs1, StringComparison.OrdinalIgnoreCase) ||

                        itm.EndsWith(MagicStrings.Ext.DotTxt, StringComparison.OrdinalIgnoreCase) ||

                        itm.EndsWith(MagicStrings.Ext.DotMd, StringComparison.OrdinalIgnoreCase) ||

                        // .exe must be excluded for service configuration to work
                        (pc.IsWindowsService && itm.EndsWith(exeName, StringComparison.OrdinalIgnoreCase))
                    ;

                    // this is an "include" filter
                    return(!exclude);
                })
            };

            packageContents.AddRange(
                new DirectoryInfo(opts.PackageInDir)
                .GetDirectories()
                .Select(dir => dir.Name)
                .Except(pc.MutableDirs)
                .Select(dirName =>
                        new Dir(
                            dirName,
                            new Files(Path.Combine(
                                          opts.PackageInDir,
                                          dirName,
                                          MagicStrings.Files.All)))));

            packageContents.Add(pc.IsWindowsService ? service : null);
            project.AddProperty(new Property("WIXUI_EXITDIALOGOPTIONALTEXT",
                                             $"NOTE: {serviceDisplayName} Windows service.\n"));

            var dataContents = new List <WixEntity>();
            var extraDir     = Path.Combine(opts.ExtraDir, ap.TargetName);

            dataContents.AddRange(
                new DirectoryInfo(extraDir)
                .GetFiles(MagicStrings.Files.AllDotYml, SearchOption.TopDirectoryOnly)
                .Select(fi =>
            {
                var wf = new WixSharp.File(fi.FullName);
                return(wf);
            }));

            dataContents.AddRange(
                new DirectoryInfo(extraDir)
                .GetDirectories()
                .Select(dir => dir.Name)
                .Select(dirName =>
                        new Dir(
                            dirName,
                            new Files(Path.Combine(
                                          extraDir,
                                          dirName,
                                          MagicStrings.Files.All)))));

            // Drop CLI shim on disk
            var cliShimScriptPath = Path.Combine(
                opts.PackageOutDir,
                MagicStrings.Files.ProductCliShim(ap.CanonicalTargetName));

            System.IO.File.WriteAllText(cliShimScriptPath, Resources.GenericCliShim);

            var beatsInstallPath =
                $"[ProgramFiles{(ap.Is64Bit ? "64" : string.Empty)}Folder]" +
                Path.Combine(companyName, productSetName);

            project.Dirs = new[]
            {
                // Binaries
                new InstallDir(
                    // Wix# directory parsing needs forward slash
                    beatsInstallPath.Replace("Folder]", "Folder]\\"),
                    new Dir(
                        ap.Version,
                        new Dir(ap.CanonicalTargetName, packageContents.ToArray()),
                        new WixSharp.File(cliShimScriptPath))),

                // Configration and logs
                new Dir("[CommonAppDataFolder]",
                        new Dir(companyName,
                                new Dir(productSetName,
                                        new Dir(ap.CanonicalTargetName, dataContents.ToArray())
                                        , new DirPermission("Users", "[MachineName]", GenericPermission.All)
                                        )))
            };

            // CLI Shim path
            project.Add(new EnvironmentVariable("PATH", Path.Combine(beatsInstallPath, ap.Version))
            {
                Part = EnvVarPart.last
            });

            // We hard-link Wix Toolset to a known location
            Compiler.WixLocation = Path.Combine(opts.BinDir, "WixToolset", "bin");

#if !DEBUG
            if (opts.KeepTempFiles)
#endif
            {
                Compiler.PreserveTempFiles = true;
            }

            if (opts.Verbose)
            {
                Compiler.CandleOptions += " -v";
                Compiler.LightOptions  += " -v";
            }

            project.ResolveWildCards();

            if (opts.WxsOnly)
            {
                project.BuildWxs();
            }
            else if (opts.CmdOnly)
            {
                Compiler.BuildMsiCmd(project, Path.Combine(opts.SrcDir, opts.PackageName) + ".cmd");
            }
            else
            {
                Compiler.BuildMsi(project);
            }
        }
    private Dir AddProgramFiles(string rootPath, Dir parentDir, MsiDirectory directory)
    {
        var path = rootPath + @"\" + directory.RelativePath;

        var newDir = new Dir()
        {
            Name = directory.Name
        };

        var fileLength = parentDir.Files.Length;
        var newFileList = new File[fileLength + directory.MsiFiles.Count];
        parentDir.Files.CopyTo(newFileList, 0);

        var startIndex = parentDir.Files.Length;
        foreach (var file in directory.MsiFiles)
        {
            newFileList[startIndex] = new File(file.Path);
            startIndex ++;
        }

        newDir.Files = newFileList;

        foreach (var subDir in directory.MsiDirectories)
        {
            AddProgramFiles(rootPath, newDir, subDir);
        }

        var length = parentDir.Dirs.Length;
        var newList = new Dir[length + 1];
        parentDir.Dirs.CopyTo(newList, 0);
        newList[length] = newDir;
        parentDir.Dirs = newList;

        return newDir; 
    }
示例#7
0
        static void Main(string[] args)
        {
            try
            {
                WixSharp.File ui = new WixSharp.File(
                    @"cli\WindowsServiceTestClient.exe",
                    new WixSharp.FileShortcut("WindowsServiceTestClient", @"%ProgramMenu%\cocoalix")
                {
                    Advertise = true
                }
                    );
                WixSharp.File service = new WixSharp.File(
                    @"service\WindowsServiceTest.exe"
                    );
                WixSharp.Files uiDepends = new WixSharp.Files(
                    @"cli\*.*"
                    );
                WixSharp.Files serviceDepends = new WixSharp.Files(
                    @"service\*.*"
                    );

                var dir = new WixSharp.Dir(new WixSharp.Id("InstallDir"),
                                           @"%ProgramFiles%\cocoalix",
                                           // インストーラーにインクルードするファイル
                                           ui,
                                           // インストーラーにインクルードするファイル
                                           service,
                                           uiDepends,
                                           serviceDepends
                                           );

                var project = new WixSharp.ManagedProject("ウィンドウズサービステスト", dir);

                project.Platform = Platform.x64;

                // 日本語をインストーラ及びWiXで仕様するためのおまじない
                project.Codepage = "932";
                project.Language = "ja-JP";

                // アップグレードコードを指定 (変更厳禁)
                project.GUID = new Guid("abbb7cf9-19fa-45f2-babc-a35312741772");

                // インストーラーのファイル名
                project.OutFileName = "ウィンドウズサービステストインストーラ";

                service.ServiceInstaller = new WixSharp.ServiceInstaller
                {
                    Account      = @"NT Authority\System",
                    PermissionEx = new WixSharp.PermissionEx()
                    {
                        User = @"Administrator",
                        ServicePauseContinue = false,
                        ServiceStart         = true,
                        ServiceStop          = true,
                    },
                    Name                    = "WindowsServiceTestService",
                    Description             = "ウィンドウズサービステストのサービスです",
                    StartOn                 = WixSharp.SvcEvent.Install,
                    StopOn                  = WixSharp.SvcEvent.InstallUninstall_Wait,
                    RemoveOn                = WixSharp.SvcEvent.Uninstall_Wait,
                    DelayedAutoStart        = true,
                    FirstFailureActionType  = WixSharp.FailureActionType.restart,
                    SecondFailureActionType = WixSharp.FailureActionType.restart,
                    ThirdFailureActionType  = WixSharp.FailureActionType.none,
                    PreShutdownDelay        = 1000 * 60 * 3,
                    ServiceSid              = WixSharp.ServiceSid.none,
                };

                // インストーラで表示するウィンドウ群の指定
                project.ManagedUI = new WixSharp.ManagedUI();
                project.ManagedUI.InstallDialogs.Add(WixSharp.Forms.Dialogs.Welcome)
                .Add(WixSharp.Forms.Dialogs.Licence)
                .Add(WixSharp.Forms.Dialogs.Progress)
                .Add(WixSharp.Forms.Dialogs.Exit);

                project.LicenceFile = @"Eula.rtf";

                // インストール時権限昇格
                project.InstallPrivileges = InstallPrivileges.elevated;
                project.InstallScope      = InstallScope.perMachine;

                project.PreserveTempFiles = true;

                var projectMsi = project.BuildMsi();

                var bootstrapper = new Bundle(
                    "ウィンドウズサービステスト_バンドルインストーラ",
                    new ExePackage()
                {
                    Id               = "DotNet5DesktopRuntime",
                    Name             = "dotnet5-windowsdesktop-runtime-5.0-win-x64.exe",
                    Vital            = true,
                    Permanent        = false,
                    DownloadUrl      = @"https://download.visualstudio.microsoft.com/download/pr/7a5d15ae-0487-428d-8262-2824279ccc00/6a10ce9e632bce818ce6698d9e9faf39/windowsdesktop-runtime-5.0.4-win-x64.exe",
                    InstallCommand   = "/install /quiet",
                    RepairCommand    = "/repair /quiet",
                    UninstallCommand = "/uninstall /quiet",
                    LogPathVariable  = "dotnet5desktopruntime.log",
                    Compressed       = true,

                    // RemotePayloadは以下のコマンドで取得可能
                    // heat payload <バンドルしたいexeのバイナリのパス> -out .\remote.xml
                    RemotePayloads = new[]
                    {
                        new RemotePayload()
                        {
                            ProductName           = "Microsoft Windows Desktop Runtime - 5.0.4 (x64)",
                            Description           = "Microsoft Windows Desktop Runtime - 5.0.4 (x64)",
                            Hash                  = "33FBCDB6B6F052FCC26B4EF850B81ED5F2C10B02",
                            Size                  = 54790696,
                            Version               = "5.0.4.29817".ToRawVersion(),
                            CertificatePublicKey  = "3756E9BBF4461DCD0AA68E0D1FCFFA9CEA47AC18",
                            CertificateThumbprint = "2485A7AFA98E178CB8F30C9838346B514AEA4769"
                        }
                    }
                },
                    new MsiPackage(projectMsi)
                    );

                // ランタイムバンドルインストーラのバージョン
                bootstrapper.Version = new Version("1.0.0.0");

                // ランタイムバンドルインストーラのアップグレードコード (変更厳禁)
                bootstrapper.UpgradeCode = new Guid("bf3b1aeb-12c5-4401-ad23-6a49f905bd55");

                // ランタイムバンドルインストーラのアプリケーションスタイルの定義
                bootstrapper.Application             = new LicenseBootstrapperApplication();
                bootstrapper.Application.LicensePath = @".\Eula.rtf";

                bootstrapper.Application.LocalizationFile = "thm.wxl";

                // インストール時のOption非表示
                bootstrapper.Application.SuppressOptionsUI = true;
                // アンインストール時の修復を非表示
                bootstrapper.Application.SuppressRepair = true;

                // 一次領域を使用するか
                bootstrapper.PreserveTempFiles = true;
                // Wixの必須パラメータの定義?は行わない
                bootstrapper.SuppressWixMbaPrereqVars = false;

                // インストーラ名の定義
                bootstrapper.OutFileName = "ウィンドウズサービステスト_バンドルインストーラ";

                // ランタイムバンドルインストーラの作成
                bootstrapper.Build();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    static private WixSharp.File RenamedFile(string source, string name)
    {
        var file = new WixSharp.File(source);
        file.Attributes["Name"] = name;

        return file;
    }
示例#9
0
        static void Main(string[] args)
        {
            var opts = CmdLineOptions.Parse(args);

            var config = BuildConfiguration.Read(
                Path.Combine(opts.ConfigDir, MagicStrings.Files.ConfigYaml));

            Directory.CreateDirectory(opts.PackageOutDir);

            if (!ArtifactPackage.FromFilename(opts.PackageName, out var ap))
            {
                throw new Exception("Unable to parse file name: " + opts.PackageName);
            }

            var pc = config.GetProductConfig(ap.TargetName);

            var companyName    = MagicStrings.Elastic;
            var productSetName = MagicStrings.Beats.Name;
            var displayName    = MagicStrings.Beats.Name + " " + ap.TargetName;
            var exeName        = ap.CanonicalTargetName + MagicStrings.Ext.DotExe;

            // Generate UUID v5 from product properties.
            // This UUID *must* be stable and unique between Beats.
            var upgradeCode = Uuid5.FromString(ap.CanonicalTargetName);

            var project = new Project(displayName)
            {
                InstallerVersion = 500,

                GUID = upgradeCode,

                Name = $"{displayName} {ap.SemVer} ({ap.Architecture})",

                Description = pc.Description,

                OutFileName = Path.Combine(opts.PackageOutDir, opts.PackageName),
                Version     = new Version(ap.Version),

                // We massage LICENSE.txt into .rtf below
                LicenceFile = Path.Combine(
                    opts.PackageOutDir,
                    MagicStrings.Files.PackageLicenseRtf(opts.PackageName)),

                Platform = ap.Is32Bit ? Platform.x86 : Platform.x64,

                InstallScope = InstallScope.perMachine,

                UI = WUI.WixUI_Minimal,

                // TODO: Custom images?
                BannerImage     = Path.Combine(opts.ResDir, MagicStrings.Files.TopBannerBmp),
                BackgroundImage = Path.Combine(opts.ResDir, MagicStrings.Files.LeftBannerBmp),

                MajorUpgrade = new MajorUpgrade
                {
                    AllowDowngrades          = false,
                    AllowSameVersionUpgrades = false,
                    DowngradeErrorMessage    = MagicStrings.Errors.NewerVersionInstalled,
                },
            };

            project.Include(WixExtension.UI);
            project.Include(WixExtension.Util);

            project.ControlPanelInfo = new ProductInfo
            {
                Contact      = companyName,
                Manufacturer = companyName,
                UrlInfoAbout = "https://www.elastic.co",

                Comments = pc.Description + ". " + MagicStrings.Beats.Description,

                ProductIcon = Path.Combine(
                    opts.ResDir,
                    Path.GetFileNameWithoutExtension(exeName) + MagicStrings.Ext.DotIco),

                NoRepair = true,
            };

            // Convert LICENSE.txt to something richedit control can render
            System.IO.File.WriteAllText(
                Path.Combine(
                    opts.PackageOutDir,
                    MagicStrings.Files.PackageLicenseRtf(opts.PackageName)),
                MagicStrings.Content.WrapWithRtf(
                    System.IO.File.ReadAllText(
                        Path.Combine(opts.PackageInDir, MagicStrings.Files.LicenseTxt))));

            var beatConfigPath = "[CommonAppDataFolder]" + Path.Combine(companyName, productSetName, ap.CanonicalTargetName);
            var beatDataPath   = Path.Combine(beatConfigPath, "data");
            var beatLogsPath   = Path.Combine(beatConfigPath, "logs");

            var textInfo           = new CultureInfo("en-US", false).TextInfo;
            var serviceDisplayName = $"{companyName} {textInfo.ToTitleCase(ap.TargetName)} {ap.SemVer}";

            WixSharp.File service = null;
            if (pc.IsWindowsService)
            {
                service = new WixSharp.File(Path.Combine(opts.PackageInDir, exeName));

                // TODO: CNDL1150 : ServiceConfig functionality is documented in the Windows Installer SDK to
                //                  "not [work] as expected." Consider replacing ServiceConfig with the
                //                  WixUtilExtension ServiceConfig element.

                service.ServiceInstaller = new ServiceInstaller
                {
                    Interactive = false,

                    Name        = ap.CanonicalTargetName,
                    DisplayName = serviceDisplayName,
                    Description = pc.Description,

                    DependsOn = new[]
                    {
                        new ServiceDependency(MagicStrings.Services.Tcpip),
                        new ServiceDependency(MagicStrings.Services.Dnscache),
                    },

                    Arguments =
                        " --path.home " + ("[INSTALLDIR]" + Path.Combine(ap.Version, ap.CanonicalTargetName)).Quote() +
                        " --path.config " + beatConfigPath.Quote() +
                        " --path.data " + beatDataPath.Quote() +
                        " --path.logs " + beatLogsPath.Quote() +
                        " -E logging.files.redirect_stderr=true",

                    DelayedAutoStart = false,
                    Start            = SvcStartType.auto,

                    // Don't start on install, config file is likely not ready yet
                    //StartOn = SvcEvent.Install,

                    StopOn   = SvcEvent.InstallUninstall_Wait,
                    RemoveOn = SvcEvent.InstallUninstall_Wait,
                };
            }

            var packageContents = new List <WixEntity>
            {
                new DirFiles(Path.Combine(opts.PackageInDir, MagicStrings.Files.All), path =>
                {
                    var itm = path.ToLower();

                    bool exclude =

                        // configuration will go into mutable location
                        itm.EndsWith(MagicStrings.Ext.DotYml, StringComparison.OrdinalIgnoreCase) ||

                        // we install/remove service ourselves
                        itm.EndsWith(MagicStrings.Ext.DotPs1, StringComparison.OrdinalIgnoreCase) ||

                        // .exe must be excluded for service configuration to work
                        (pc.IsWindowsService && itm.EndsWith(exeName, StringComparison.OrdinalIgnoreCase))
                    ;

                    // this is an "include" filter
                    return(!exclude);
                })
            };

            packageContents.AddRange(
                new DirectoryInfo(opts.PackageInDir)
                .GetDirectories()
                .Select(dir => dir.Name)
                .Except(pc.MutableDirs)
                .Select(dirName =>
                        new Dir(
                            dirName,
                            new Files(Path.Combine(
                                          opts.PackageInDir,
                                          dirName,
                                          MagicStrings.Files.All)))));

            packageContents.Add(pc.IsWindowsService ? service : null);

            // Add a note to the final screen and a checkbox to open the directory of .example.yml file
            var beatConfigExampleFileName = ap.CanonicalTargetName + ".example" + MagicStrings.Ext.DotYml;
            var beatConfigExampleFileId   = beatConfigExampleFileName + "_" + (uint)beatConfigExampleFileName.GetHashCode32();

            project.AddProperty(new Property("WIXUI_EXITDIALOGOPTIONALTEXT",
                                             $"NOTE: Only Administrators can modify configuration files! We put an example configuration file " +
                                             $"in the data directory caled {ap.CanonicalTargetName}.example.yml. Please copy this example file to " +
                                             $"{ap.CanonicalTargetName}.yml and make changes according to your environment. Once {ap.CanonicalTargetName}.yml " +
                                             $"is created, you can configure {ap.CanonicalTargetName} from your favorite shell (in an elevated prompt) " +
                                             $"and then start {serviceDisplayName} Windows service.\r\n"));

            project.AddProperty(new Property("WIXUI_EXITDIALOGOPTIONALCHECKBOX", "1"));
            project.AddProperty(new Property("WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT",
                                             $"Open {ap.CanonicalTargetName} data directory in Windows Explorer"));

            // We'll open the folder for now
            // TODO: select file in explorer window
            project.AddProperty(new Property(
                                    "WixShellExecTarget",
                                    $"[$Component.{beatConfigExampleFileId}]"));

            project.AddWixFragment("Wix/Product",
                                   XElement.Parse(@"
<CustomAction
    Id=""CA_SelectExampleYamlInExplorer""
    BinaryKey = ""WixCA""
    DllEntry = ""WixShellExec""
    Impersonate = ""yes""
/>"),
                                   XElement.Parse(@"
<UI>
    <Publish
        Dialog=""ExitDialog""
        Control=""Finish""
        Event=""DoAction"" 
        Value=""CA_SelectExampleYamlInExplorer"">WIXUI_EXITDIALOGOPTIONALCHECKBOX=1 and NOT Installed
    </Publish>
</UI>"));

            var dataContents = new DirectoryInfo(opts.PackageInDir)
                               .GetFiles(MagicStrings.Files.AllDotYml, SearchOption.TopDirectoryOnly)
                               .Select(fi =>
            {
                var wf = new WixSharp.File(fi.FullName);

                // rename main config file to hide it from MSI engine and keep customizations
                if (string.Compare(
                        fi.Name,
                        ap.CanonicalTargetName + MagicStrings.Ext.DotYml,
                        StringComparison.OrdinalIgnoreCase) == 0)
                {
                    wf.Attributes.Add("Name", beatConfigExampleFileName);
                    wf.Id = new Id(beatConfigExampleFileId);
                }

                return(wf);
            })
                               .ToList <WixEntity>();

            dataContents.AddRange(
                pc.MutableDirs
                .Select(dirName =>
            {
                var dirPath = Path.Combine(opts.PackageInDir, dirName);

                return(Directory.Exists(dirPath)
                            ? new Dir(dirName, new Files(Path.Combine(dirPath, MagicStrings.Files.All)))
                            : null);
            })
                .Where(dir => dir != null));

            // Drop CLI shim on disk
            var cliShimScriptPath = Path.Combine(
                opts.PackageOutDir,
                MagicStrings.Files.ProductCliShim(ap.CanonicalTargetName));

            System.IO.File.WriteAllText(cliShimScriptPath, Resources.GenericCliShim);

            var beatsInstallPath =
                $"[ProgramFiles{(ap.Is64Bit ? "64" : string.Empty)}Folder]" +
                Path.Combine(companyName, productSetName);

            project.Dirs = new[]
            {
                // Binaries
                new InstallDir(
                    // Wix# directory parsing needs forward slash
                    beatsInstallPath.Replace("Folder]", "Folder]\\"),
                    new Dir(
                        ap.Version,
                        new Dir(ap.CanonicalTargetName, packageContents.ToArray()),
                        new WixSharp.File(cliShimScriptPath))),

                // Configration and logs
                new Dir("[CommonAppDataFolder]",
                        new Dir(companyName,
                                new Dir(productSetName,
                                        new Dir(ap.CanonicalTargetName, dataContents.ToArray())
                {
                    GenericItems = new []
                    {
                        /*
                         * This will *replace* ACL on the {beatname} directory:
                         *
                         * Directory tree:
                         *  NT AUTHORITY\SYSTEM:(OI)(CI)F
                         *  BUILTIN\Administrators:(OI)(CI)F
                         *  BUILTIN\Users:(CI)R
                         *
                         * Files:
                         *  NT AUTHORITY\SYSTEM:(ID)F
                         *  BUILTIN\Administrators:(ID)F
                         */

                        new MsiLockPermissionEx(
                            "D:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;CI;0x1200a9;;;BU)",
                            ap.Is64Bit)
                    }
                })))
            };

            // CLI Shim path
            project.Add(new EnvironmentVariable("PATH", Path.Combine(beatsInstallPath, ap.Version))
            {
                Part = EnvVarPart.last
            });

            // We hard-link Wix Toolset to a known location
            Compiler.WixLocation = Path.Combine(opts.BinDir, "WixToolset", "bin");

#if !DEBUG
            if (opts.KeepTempFiles)
#endif
            {
                Compiler.PreserveTempFiles = true;
            }

            if (opts.Verbose)
            {
                Compiler.CandleOptions += " -v";
                Compiler.LightOptions  += " -v";
            }

            project.ResolveWildCards();

            if (opts.WxsOnly)
            {
                project.BuildWxs();
            }
            else if (opts.CmdOnly)
            {
                Compiler.BuildMsiCmd(project, Path.Combine(opts.SrcDir, opts.PackageName) + ".cmd");
            }
            else
            {
                Compiler.BuildMsi(project);
            }
        }