Wixsharp: Question: Multiple root level directories

Created on 10 Oct 2017  路  11Comments  路  Source: oleg-shilo/wixsharp

I need multiple root level directories

  1. %ProgramFiles%\MyProduct
  2. %ProgramFiles%\MSBuild\MyProduct

The first path should be INSTALLLOCATION and can be changed by the user. The second directory should be fixed and not be changeable.

In our Wix based setup we achieved it by something like:

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLLOCATION" Name="$(var.ProductDir)" />
      </Directory>
    </Directory>
...
<Fragment>
    <DirectoryRef Id="ProgramFilesFolder">
            <Directory Id="MSBuildFolder" Name="MSBuild">
                <Directory Id="MSBuildTargetsFolder" Name="$(var.MSBuildDir)$(var.ProductVariant)" FileSource="..\bin\$(var.Configuration)">
                    ...
                </Directory>
            </Directory>
        </DirectoryRef>
</Frament>

I did not find any way to use a DirectoryRef element via WixSharp.

Is it possible to achieve the described scenario with WixSharp? And if so, how?

Side Note: Using two root dirs with %ProgramFiles% leads to the error:

Duplicate symbol 'Directory:ProgramFilesFolder' 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.
enhancement question

All 11 comments

This is what you are looking for:
```C#
var project = new ManagedProject("Test",
new Dir("%ProgramFiles%",
new Dir(new Id("INSTALLLDIR"), "MyProduct", new File("setup.cs")),
new Dir(@"MSBuild\MyProduct", new File("readme.txt"))));

project.BuildMsi();
```

Note I have used an explicit id assignment of the _INSTALLDIR_ because otherwise Wix# automatically assigns it to the first directory in the directories declaration (and this is not what you want).

You can assign _INSTALLLOCATION_ but it is better to keep the id as _INSTALLDIR_. This is because this value has special meaning across MSI domain. It has been used to bind directory to the textbox in the _InstallDirDialog_.

Using _INSTALLLOCATION_ is still possible but then you will need to take extra steps to ensure it is properly integrated with the rest of MSI infrastructure.

That solved my issue.

Thanks a lot.

Unfortunately this does not work anymore - using the WixSharp 1.6.1. - it creates the files in the wrong folders:

ActionStart: ... 3: J:\ProgramFilesFolder\MyProduct\setup.cs
ActionData: ... 3: J:\ProgramFilesFolder\MSBuild\MyProduct\readme.txt

Could this be related to the latest changes regarding Ids?

The created .wxs looks like this (which seems wrong - double INSTALLDIR and ProgramFilesFolders should actually be the Id and not the Name):

<Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="INSTALLDIR" Name="ProgramFilesFolder">
        <Directory Id="INSTALLLDIR" Name="MyProduct">

Thanks

found it! You must now manually set IsInstallDir = true, like this:

var project = new ManagedProject("Test",
                    new Dir("%ProgramFiles%",
                        new Dir(new Id("INSTALLLDIR"), "MyProduct", new File("setup.cs")) { IsInstallDir = true },
                        new Dir(@"MSBuild\MyProduct", new File("readme.txt"))));

project.BuildMsi();

Great.

Though I am now questioning the dev friendliness of the solution.

Right now if you don't explicitly set the IsInstallDir the emitted WXS for the cases like yours is not what the user anticipated.

WixShrp produces the warning:

WARNING: Special folder directory ID 'ProgramFilesFolder' has been reset to 'INSTALLDIR'.
If it was not intended disable auto assignment by setting 'Compiler.AutoGeneration.InstallDirDefaultId' to null.

I am going to extend the warning message with Or set IsInstallDir = true for the installation directory.

Though the fact that you missed it indicates that this error notification mechanism is not entirely reliable. Adequate but not the best.

I am thinking about the dedicated class InstallDir that is the same as Dir except it already has IsInstallDir set to true:

```C#
var project =
new ManagedProject("Test",
new Dir("%ProgramFiles%",
new InstallDir("MyProduct",
new File("setup.cs")),
new Dir(@"MSBuild\MyProduct", new File("readme.txt"))));

project.BuildMsi();
```
Will it be a friendlier solution?

I did not notice that warning, never seen it before (just tried again - it is indeed as the first line of output but due to the long build output I've missed it).

It seems this used to work "per default" (as per this thread's original intention) but it does not anymore.

Personally (due to my lack of knowlegde in MSI) the "IsInstallDir" property was unknown to me, found it by "chance" - so although a new InstallDir() overload would help - I think also a new sample showing/describing this scenario would be great (I love the samples and appreciate them way more than any documentation).

Thanks

Just another comment:

Right now if you don't explicitly set the IsInstallDir the emitted WXS for the cases like yours is not what the user anticipated

That's because of this:

new Dir(new Id("INSTALLLDIR"), "MyProduct", new File("setup.cs")) { IsInstallDir = true },

I would expect that if I set Id("INSTALLDIR") it would be clear this is the IsInstallDir (even with automated Id generation), I think that's what got me and has been changed since the original implementation.

Cheers

Great.

The warning is updated wth the suggestion to use InstallDir class.
The sample "InstallDir" is already reworked.
The rest of the samples will be reworked gradually.
Wiki is yet to be updated.

As for this scenario working in prev release, you guessed correctly somewhere the connection between INSTALLDIR and being install dir has been broken.

However this connection was useful but not perfect. WiX/MSI allows any ID for the install dir. Thus I actually prefer the dedicated class as it is more explicit.

I think the Wiki topic of _Installation Directory_ was not covered sufficiently enough so I reworked it. It now reflects all the points that we discussed here: https://github.com/oleg-shilo/wixsharp/wiki/Deployment-scenarios

Great, THANK you!

Be careful the unfolding may lead to some expected results when used without a proper attention:

I think you meant here "..to some unexpected results..."

Cheers

Of course . Thanks. 馃憤
Fixed now

Was this page helpful?
0 / 5 - 0 ratings