Wixsharp: MSI setup suggests wrong installation folder

Created on 15 Jan 2019  路  2Comments  路  Source: oleg-shilo/wixsharp

In my WixSharp project, I'm specifying the root folder as:

private static Project createProject(DirectoryInfo tempFilesRoot)
{
    var wixObjects = new List<WixObject>();

    // --

    var rootDir =
        new Dir(
            new Id(@"APPLICATIONROOTDIRECTORY"),
            @"%ProgramFiles%\Zeta Test");

    buildTree(
        rootDir,
        tempFilesRoot);

    wixObjects.Add(rootDir);

    // ...

Still, when installing, it suggests "E:\ProgramFilesFolder":

image

The correct path would be "C:\Program Files" or "C:\Program Files (x86)".

I'm really clueless and checked alle examples, issues here on Github and still found no solution.

When executing set on the command line, it outputs, among others, this:

ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)

So I do think, my environment variables are correctly set (in case it matters).

My question:

How can I acchieve that the default installation folder is being set to the actual program files (or x86) folder?

Most helpful comment

Actually your suggestion in this issue helped me out.

I'm now doing:

private static Project createProject(DirectoryInfo tempFilesRoot)
{
    var wixObjects = new List<WixObject>();

    // --

    var myRootDir = new Dir(new Id(@"INSTALLLDIR"), "Zeta Test");
    var rootDir = new Dir(@"%ProgramFiles%", myRootDir);

    buildTree(myRootDir, tempFilesRoot);

    wixObjects.Add(rootDir);

    // ...

And until now, everything looks OK and working.

All 2 comments

The problem you are experiencing is caused by the way you are accessing the installation dir.

WiX does not support root directory expressed as path (e.g. @"%ProgramFiles%\Zeta Test"). It forces user to use multiple nested elements. This would require creating Dir object twice in your case:
```C#
new Dir("%ProgramFiles%",
new Dir("Zeta Test",

While WixSharp allows simplified syntax with the full path in a single `Dir` object one needs to be aware about what is happening under the hood. This article explains the details: https://github.com/oleg-shilo/wixsharp/wiki/Deployment-scenarios#installation-directory.

Thus the solution for your case would be around the correct access to the install dir:
```C#
var rootDir = new Dir(new Id(@"APPLICATIONROOTDIRECTORY"), @"%ProgramFiles%\Zeta Test"); // ProgramFiles
var installDir = rootDir.Dirs[0]; // "Zeta Test"

Actually your suggestion in this issue helped me out.

I'm now doing:

private static Project createProject(DirectoryInfo tempFilesRoot)
{
    var wixObjects = new List<WixObject>();

    // --

    var myRootDir = new Dir(new Id(@"INSTALLLDIR"), "Zeta Test");
    var rootDir = new Dir(@"%ProgramFiles%", myRootDir);

    buildTree(myRootDir, tempFilesRoot);

    wixObjects.Add(rootDir);

    // ...

And until now, everything looks OK and working.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kain64 picture kain64  路  4Comments

ayman-eltemsahi picture ayman-eltemsahi  路  4Comments

ju2pom picture ju2pom  路  5Comments

meytes picture meytes  路  3Comments

marcobeninca71 picture marcobeninca71  路  4Comments