Maintain directory structure

Apr 8, 2016 at 3:32 PM
I've been trying to create an installation msi, but I keep getting duplicate id error and I have no idea what I'm doing wrong. I tried to add my own identifiers, but the installation fails.

The error: Duplicate symbol 'Directory:INSTALLDIR.myFolder' found. This typically means that an Id is duplicated. Check to make sure all your identifiers of a given type (File, Component, Feature) are unique.

Additionally, and unrelated, I tried to do a silent install with a generated msi, but I'm only able to get it to actually install if I run with elevated privileges. Is there a way to perform a silent install from any command input?

Thank you. :)

Here's the code:
    static void Main(string[] args)
    {
        var dir = PopulateDir("myFolder", true);

        var project = new Project("a_myApp", dir);

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

        Compiler.PreserveTempFiles = true;
        Compiler.BuildMsi(project);
    }

    private static Dir PopulateDir(string sDir, bool isRoot)
    {
        Dir dir;
        try
        {
            var fileList = System.IO.Directory.GetFiles(sDir);
            var dirList = System.IO.Directory.GetDirectories(sDir);

            WixEntity[] eList = new WixEntity[fileList.Length + dirList.Length];

            for (int i = 0; i < fileList.Length; i++)
                eList[i] = new File(fileList[i]);

            for (int i = 0, e = fileList.Length; i < dirList.Length; i++, e++)
                eList[e] = PopulateDir(dirList[i], false);

            if (isRoot)
                dir = new Dir(@"%ProgramFiles%\ACompany\myApp", eList);
            else
                dir = new Dir(sDir, eList);
        }
        catch
        {
            return null;
        }

        return dir;
    }
Apr 8, 2016 at 4:12 PM
I figured out the problem with the ID's, the code will be bellow for whoever faces the same issue.
The issue where silent mode requires elevated privileges remains and now I have a new problem. I want to make per-user installations and redirect them to the user datafolder. I haven't been able to find any documentation on this yet.


Fix:
    static void Main(string[] args)
    {
        var dir = PopulateDir("myFolder", true);

        var project = new Project("a_myApp", dir);

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

        Compiler.PreserveTempFiles = true;
        Compiler.BuildMsi(project);
    }

    static int count = 0;

    private static Dir PopulateDir(string sDir, bool isRoot)
    {
        Dir dir;
        try
        {
            var fileList = System.IO.Directory.GetFiles(sDir);

            var dirList = System.IO.Directory.GetDirectories(sDir);

            WixEntity[] eList = new WixEntity[fileList.Length + dirList.Length];

            for (int i = 0; i < fileList.Length; i++)
            {
                //fileList[i] = System.IO.Path.GetFileName(fileList[i]);
                eList[i] = new File(fileList[i]);
            }
            for (int i = 0, e = fileList.Length; i < dirList.Length; i++, e++)
                eList[e] = PopulateDir(dirList[i], false);
            //string dirname = System.IO.Path.GetDirectoryName(sDir);

            var dirname = new System.IO.DirectoryInfo(sDir).Name;

            if (isRoot)
                dir = new Dir(@"%ProgramFiles%\ACompany\myApp", eList);
            else
                dir = new Dir(dirname, eList);

            if (!isRoot)
                dir.Id = "dir" + count++;
        }
        catch
        {
            return null;
        }

        return dir;
    }
Apr 8, 2016 at 4:20 PM
Changing %ProgramFiles% to %LocalAppDataFolder% solved both issues. :)
Coordinator
Apr 10, 2016 at 4:04 AM
It looks like you are trying to do what is already implemented as a Wix# native feature :)

You can add the whole directory with the files in a single step:
var project =
    new Project("MyProduct",
        new Dir(@"%ProgramFiles%\My Company\My Product",
            new Files(@"..\Release Folder\Release\*.*",...
Have a look at "ReleaseFiolder" and "WildCard Files" samples.
Apr 11, 2016 at 9:17 AM
Thanks, that did the trick. :)