Error when consuming Merge Modules

May 24, 2016 at 1:33 PM

When using the sample source code for consuming MergeModules, I do not receive any errors:

var project =
            new Project("MyMergeModuleSetup",
                new Dir(@"%ProgramFiles%\My Company",
                    new File(featureA, @"Files\MainFile.txt"),
                    new Merge(featureB, @"Files\MyMergeModule.msm"),
                    new Merge(featureB, @"Files\MyMergeModule1.msm")));

However, if I was to remove "new File(featureA, @"Files\MainFile.txt")" so that the project only contains the install directory and the merge modules, I get the following error:

System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at WixSharp.Compiler.GetTopLevelDir(XElement product)
at WixSharp.Compiler.GenerateWixProj(Project project)
at WixSharp.Compiler.BuildWxs(Project project, String path, OutputType type)
at WixSharp.Compiler.BuildWxs(Project project, OutputType type)
at CommonLibrary.WixUtils.WixProject.BuildWxsFile(Package package) in U:\Bare
Metal-Windows\CommonLibrary\WixUtils\WixProject.cs:line 84

Do we have to include a directory or a file in the project along with the reference to the merge modules, in order to create an MSI? Is this a bug?

May 25, 2016 at 6:51 AM
Actually it is a WiX limitation. You need to have a directory if you want to install msm. Merge module can only be hosted by a Directory element.

Tujough you don't have to have a file for that. Thus I tested your change with the same sample file and it seems to work. At least with the latest release (v1.0.36.3). Probably it's better if you grab the latest binaries from NuGet. This is the code I tested:
static public void Main(string[] args)
    var featureA = new Feature("Feature A", "Feature A description");
    var featureB = new Feature("Feature B", "Feature B description");
    var complete = new Feature("Complete");


    var project =
            new Project("MyMergeModuleSetup",
                new Dir(@"%ProgramFiles%\My Company",
                    //new File(featureA, @"Files\MainFile.txt"),
                    new Merge(featureB, @"Files\MyMergeModule.msm"),
                    new Merge(featureB, @"Files\MyMergeModule1.msm")));

    project.DefaultFeature = complete;
    project.UI = WUI.WixUI_FeatureTree;
    project.InstallerVersion = 200; //you may want to change it to match MSM module installer version

    project.PreserveTempFiles = true;

May 25, 2016 at 1:09 PM
Thanks so much Oleg_S! The update allowed the code to work.
May 25, 2016 at 1:14 PM
Great. The today release didn't actually contain any changes related to MSM. It must be one of the previous releases.
Though... it doesn't matter. It works :)