oleg-shilo/wixsharp

How to get Features installed path.

dorlep opened this issue · 4 comments

My Msi is installing features in separate folders and during uninstall I wanted to delete all the folders.
How can I get the path of each features where that feature has installed in Msi_AfterInstall event, so that I can delete it Programmatically.
Below is my code to create project

Feature pccwinFeature = new Feature("Job Worker Service", "Job worker", "FEATURE_INSTALL_PATH1");
Feature pccwebFeature = new Feature("PCC Portal", "Web Api", "FEATURE_INSTALL_PATH2");
Feature pModels = new Feature("Workflow Models", " Models", "FEATURE_INSTALL_PATH4");
Feature pIpc = new Feature("IPC Tomcat", " IPC Tomcat", "FEATURE_INSTALL_PATH3");

var project = new ManagedProject(productName,
          //PCC windows service
          new Dir(new Id("FEATURE_INSTALL_PATH1"), installDir,
               new Dir(windowsFolder,
              new Files(pccwinFeature, windowsSourceDir + @"\*.exe"))),
          //PCC Web
          new Dir(new Id("FEATURE_INSTALL_PATH2"), installDir,
               new Dir(wedFolder,
              new Files(pccwebFeature, webApiSourceDir + @"\*.dll"))),
         //Prophet Models
         new Dir(new Id("FEATURE_INSTALL_PATH4"), installDir,
             new Dir(prophetModelsFolder,
             new Files(pModels, pModelsSourceDir + @"\*.dll"))),
         new Dir(new Id("FEATURE_INSTALL_PATH3"), installDir,
             new Dir("Prophet IPC Tomcat",
            new Files(pIpc, iPCTomcatSourceDir + @"\*.*"))),
        new RegValue(pccwinFeature, WixSharp.RegistryHive.LocalMachine, "Software[\\PS\\P](file://ps/P)\\PCCWindows", "InstalledDirectory", "[FEATURE_INSTALL_PATH1]"),
        new RegValue(pccwebFeature, WixSharp.RegistryHive.LocalMachine, "Software\\PS\\P\\PC", "InstalledDirectory", "[FEATURE_INSTALL_PATH2]"),
        new RegValue(pIpc, WixSharp.RegistryHive.LocalMachine, "Software\\PS[\\P\\IPCWeb](file://p/IPCWeb)", "InstalledDirectory", "[FEATURE_INSTALL_PATH3]"),
       new RegValue(ipcTom, WixSharp.RegistryHive.LocalMachine, "Software\\PS[\\P\\IPCTomWeb](file://p/IPCTomWeb)", "InstalledDirectory", "[FEATURE_INSTALL_PATH4]"));

Please help me.
Thank you in advance.

In the Msi_AfterInstall you can get the installdir from the args: e.InstallDir

Thus by combining it with the feature path you can get the exact dir:

var path = e.InstallDir.PathCombine("FEATURE_INSTALL_PATH2");

. . .

Unrelated. You may improve the readability of your code if you include it in the code section. It's not obvious so sharing it with you: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks

I have fixed your message above.

Hi oleg-shilo,

Not getting the correct path, I am getting path like "C:\Temp\xyz\FEATURE_INSTALL_PATH2"
which is like combine 1st feature path and then ID.
Even I am getting only 1st feature path using e.InstallDir .
How can I get the other features path as my all features are installed in different location (like one is on F drive and one is on c drive, parent dir is not same).

Sorry. There are two problems with the code I suggested:

I meant to resolve the FEATURE_INSTALL_PATH2 property with the session object. I got confused with what that string was in your code.

And also... InstallDir is unnecessary I'm the code I shared. The whole property/dirId is set by the MSI to the complete absolute path.

This is the code you need to use. I checked it. It works:

project.DefaultDeferredProperties += ",FEATURE_INSTALL_PATH2";
project.AfterInstall += (SetupEventArgs e) =>
{
    try
    {
        MessageBox.Show(e.Session.Property("FEATURE_INSTALL_PATH2"));
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
};

And...
image

Note, project.DefaultDeferredProperties += ",FEATURE_INSTALL_PATH2"; without it, the AfterInstall cannot access this property as it is executed as deferred action and can only access deferred props.
Don't ask, it is one of those black magic MSI cases.