summaryrefslogtreecommitdiff
path: root/src/internal/WixBuildTools.TestSupport/Builder.cs
blob: ef0de8c9169e270af7145c9650fef97c837453ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixBuildTools.TestSupport
{
    using System;
    using System.Collections.Generic;
    using System.IO;

    public class Builder
    {
        public Builder(string sourceFolder, Type extensionType = null, string[] bindPaths = null, string outputFile = null)
        {
            this.SourceFolder = sourceFolder;
            this.ExtensionType = extensionType;
            this.BindPaths = bindPaths;
            this.OutputFile = outputFile ?? "test.msi";
        }

        public string[] BindPaths { get; set; }

        public Type ExtensionType { get; set; }

        public string OutputFile { get; set; }

        public string SourceFolder { get; }

        public string[] BuildAndQuery(Action<string[]> buildFunc, params string[] tables)
        {
            var sourceFiles = Directory.GetFiles(this.SourceFolder, "*.wxs");
            var wxlFiles = Directory.GetFiles(this.SourceFolder, "*.wxl");

            using (var fs = new DisposableFileSystem())
            {
                var intermediateFolder = fs.GetFolder();
                var outputPath = Path.Combine(intermediateFolder, "bin", this.OutputFile);

                var args = new List<string>
                {
                    "build",
                    "-o", outputPath,
                    "-intermediateFolder", intermediateFolder,
                };

                if (this.ExtensionType != null)
                {
                    args.Add("-ext");
                    args.Add(Path.GetFullPath(new Uri(this.ExtensionType.Assembly.CodeBase).LocalPath));
                }

                args.AddRange(sourceFiles);

                foreach (var wxlFile in wxlFiles)
                {
                    args.Add("-loc");
                    args.Add(wxlFile);
                }

                foreach (var bindPath in this.BindPaths)
                {
                    args.Add("-bindpath");
                    args.Add(bindPath);
                }

                buildFunc(args.ToArray());

                return Query.QueryDatabase(outputPath, tables);
            }
        }
    }
}