33

I have a custom action and need to get below values for copying some parts from installation folder to VS2010 folder

  1. VS2010 directory path (VS2010DEVENV property)
  2. Installation path (INSTALLLOCATION property)

To give enough privileges, I've set custom action as Execute='deferred' Impersonate='no'. But when running the installer, it logged the message:

Cannot access session details from a non-immediate custom action

It seems we cannot access a property in a "deferred" custom action (i.e session["VS2010DEVENV"])

Is there any other way so that I can retrieve those values as needed?

BartoszKP
  • 32,105
  • 13
  • 92
  • 123
jcha
  • 599
  • 1
  • 7
  • 16

2 Answers2

34

This must be helpful. Pay special attention to the bottom of the page, a guideline of 2 steps how to pass values via CustomActionData.

Here is the excerpt:

To write the value of a property into the installation script for use during a deferred execution custom action:

  1. Insert a small custom action into the installation sequence that sets the property of interest to a property having the same name as the deferred execution custom action. For example, if the primary key for the deferred execution custom action is "MyAction" set a property named "MyAction" to the property X which you need to retrieve. You must set the "MyAction" property in the installation sequence before the "MyAction" custom action. Although any type of custom action can set the context data, the simplest method is to use a property assignment custom action (for example Custom Action Type 51).
  2. At the time when the installation sequence is processed, the installer will write the value of property X into the execution script as the value of the property CustomActionData.
Yan Sklyarenko
  • 29,347
  • 24
  • 104
  • 125
  • 3
    Thanks for the [reference](http://msdn.microsoft.com/en-us/library/aa370543.aspx). The **CustomActionData** property works well. But I'm wondering how we can pass more than one value. In my case, I need both VS2010 and installation folder values. Can you give some hints if possible? – jcha Sep 05 '11 at 11:31
  • 11
    You'll have to parse the string you pass in the deferred custom action. For instance, you can pass `[VS2010DEVENV]|[INSTALLLOCATION]`, and split the CustomActionData by `|` in deferred CA. If you use DTF for your CA, it has a dictionary-like CustomActionData property, and you can pass it like `vs2010=[VS2010DEVENV];location=[INSTALLLOCATION]`, and obtain it like `session.CustomActionData["vs2010"]` and `session.CustomActionData["location"]` – Yan Sklyarenko Sep 05 '11 at 12:40
  • Great! It totally solves my case. Thank you so much for your advices. – jcha Sep 06 '11 at 03:02
  • CustomActionData link broken (page says "This Topic Is No Longer Available"). But this is pointing me in the right direction, thanks! – Epu Sep 19 '12 at 03:46
  • Is there a way, I can send all the properties present in the installation script to the Custom Action? I Have used this method, but I am unable to get the INSTALLLOCATION OR INSTALLDIR property, although I receive the TARGETDIR property. – teenup Aug 01 '13 at 07:28
21

Additional details: multiple property values can be passed by using the following syntax in a "Custom Action Type 51" (which is basically just a custom action that sets a property value):

PROPERTY1=Value1;PROPERTY2=Value2;PROPERTY3=...

Values can be retrieved from within the custom action like this:

string prop1 = session.CustomActionData["PROPERTY1"];
string prop2 = session.CustomActionData["PROPERTY2"];

Here's an example that sets property values for a custom action with ID "MyCustomAction":

<CustomAction
  Id="SetCustomActionPropertyValues"
  Property="MyCustomAction"
  Value="INSTALLDIR=[INSTALLDIR];EXECUTABLE=[#MyExecutableFile]" />

(read this MSDN article for more details on the formatted syntax which in this example is used to retrieve the install location of a file with ID "MyExecutableFile")

bernhof
  • 5,936
  • 2
  • 40
  • 66
  • 8
    Many thanks for the concrete example. Just what I needed. Future visitors should also see [this answer](http://stackoverflow.com/a/11233268/660536) for further details and examples. – GazTheDestroyer Nov 11 '15 at 11:51