Search code examples
c#windows-installercustom-actionsetup-deployment

Pass value from Launch Condition (Search Target Machine) to Custom Action in MSI


I'm creating an MSI using Visual Studio 2015. I want to check in certain file exists already in TARGETDIR and pass the result of the search to a custom action in c#. So far, I create the search in Launch Conditions view and set properties accordingly.

enter image description here

Then, I pass the property name in Custom Actions view as Custom Data Parameter:

/CONFIG_EXISTS="[CONFIG_EXISTS]"

But when I read the value in my custom action code, its value is empty, but I expect to find a bolean, at least as string.

protected override void OnAfterInstall(IDictionary savedState){
    var existingConfig = Context.Parameters["CONFIG_EXISTS"]; // Always has "" as value
    .... // Other code

What am I missing here? How to get in my custom action c# code the result of the search condition?


Solution

  • Your search is failing because it runs very early in the install, before TARGETDIR has been initialized (and keep in mind that TARGETDIR is also what can be changed by the dialog that offers an install folder). So you should redefine your search in terms of the standard Windows Installer folder properties, such as ProgramFilesFolder, CommonFilesFolder and so on, full list here:

    https://msdn.microsoft.com/en-us/library/windows/desktop/aa370905(v=vs.85).aspx#system_folder_properties