2

I am new to both Wix and WixSharp. I recently learnt Wix and created a basic installer with it. One of the properties I used was 'IniFileSearch' which helped me search a value from an IniFile and use that to find an install location for my files. I am trying to do the same using WixSharp but don't seem to find an equivalent method. The closest thing I could find in WixSharp is the 'AppSearch' class (under WixSharp.CommonTasks). From Wix I know that 'AppSearch' is a MSI database table where search tasks are stored. 'IniFileSearch' is one of those searches. I am not even sure if the 'AppSearch' class in WixSharp library is directly mapped to the 'AppSearch' MSI database table. Anyways, my goal is to find the 'IniFileSearch' equivalent method in WixSharp Library. If anybody knows it, an example would be great.

Here is a sample IniFileSearch in Wix markup

<Property Id="MY_PROPERTY">
 <IniFileSearch Id="myIniSearch"
                Name="myConfigFile.ini"
                Section="section1"
                Key="name"
                Type="raw" />
</Property>
aniketgade
  • 83
  • 2
  • 7

1 Answers1

2

Here is the answer I got from Oleg Shilo, the creator of WixSharp.

Because Wix# does many things differently such tasks as "MSI IniFileSearch property" are almost irrelevant for the Wix# story. Anyway, as far as Wix# goes RegValueProperty is the only MSI "AppSearch" task that it supports natively. Instead, Wix# allows you to specify a C# routine in which you can do ANY search/analysis without being bound by MSI functionality.

Thus in the Managed CA you can read your reg file with any C# algorithm of your choice and just update the session property as you wish:

public class CustomActions
{
    [CustomAction]
    public static ActionResult MyAction(Session session)
    {
        session["EnvVersion"] = AppSearch.IniFileValue(Environment.ExpandEnvironmentVariables(@"%windir%\win.ini"),
                                                       "System",
                                                       "Version");
    }
}

In the code above I have used the IniFileValue lookup routine that Wix# already implements but you can use any alternative implementation. Even interop GetProfileString(...).

If you use Managed Setup then you will need to place your action in the UIInitialized (or/and Load) event handler:

project.UIInitialized += project_UIInit;
...
static void project_UIInit(SetupEventArgs e)
{
    e.Session["EnvVersion"] = AppSearch.IniFileValue(Environment.ExpandEnvironmentVariables("%windir%\\config.ini"),
                                                     "System",
                                                     "Version") ?? "<unknown>"; 
}  

Just keep in mind that IniFileValue has been added only recently thus currently you can get it only from NuGet as a pre-release package:

Install-Package WixSharp.bin -Version 1.0.26
aniketgade
  • 83
  • 2
  • 7
  • **Correction** : IniFileValue needs WixSharp 1.0.27 – aniketgade Sep 29 '15 at 19:33
  • That code looks accurate to me, and if anyone would know, it would certainly be Oleg. Thank you for asking the question and posting his response. Knowing about the UIInitialized event and how to write a runtime handler for it will come in handy for me. Did you try the above code, and did it accomplish the needed task for you? – Developer63 Nov 17 '15 at 04:41