none
I have an Installer class. How do I get the installation directory?

    Question

  • I have created a custom action and have my Installer class working. But I need to know what directory the user chose during the installation process.

    I get an IDictionary passed in so I thought perhaps I could get the value from there. The MSDN indicates there is an Item method on IDictionary. But there is not. When I try to do something like:

    stateSaver.Item("TARGETDIR");

    I get a compile error (I did call Contains("TARGETDIR") and found out there is no parameter with that name.

    So how does my custom action access the installation directory chosen by the user?


    R.D. Holland

    • Moved by lucy-liu Friday, March 02, 2012 3:32 AM it is installer issue (From:Visual Studio Extensibility)
    Wednesday, February 29, 2012 10:03 PM

Answers

  • You should not be looking at statesaver.  You should be looking at Context.Parameters[ "name" ]


    Phil Wilson

    • Marked as answer by RD Holland Tuesday, March 06, 2012 2:03 PM
    Monday, March 05, 2012 11:42 PM

All replies

  • Hi RD,
    You can try to use Assembly.GetExecutingAssembly().Location. to get the installation directory.
    In addition, it is an installer issue, in order to give you a better support, I will move it to “ClickOnce and Setup & Deployment Projects”.
    Thank you for your understanding!

    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 02, 2012 3:30 AM
  • Hi Lucy,

    I have noticed that my custom action's DLL (assembly) does end up in the install directory. So perhaps GetExecutingAssembly().Location will be reliable. But actually I don't want the DLL delivered. I followed the steps in the MSDN for a custom action and I suspect picking the output of my project was a mistake. I want my action to execute but I don't want the DLL to be installed.

    Surely the setup program's custom action has some direct way to determine what dir the user chose the product to go into. Seems quite basic to me.


    R.D. Holland

    Friday, March 02, 2012 4:09 PM
  • Pass it via CustomActionData:

    http://msdn.microsoft.com/en-us/library/2w2fhwzz(v=vs.80).aspx 

    Installer classes have that context dictionary. In the exanple at that link, you get the text corresponding to "name" because /name=... was iused to pass the value.


    Phil Wilson

    Friday, March 02, 2012 6:01 PM
  • Thanks Phil,

    I'll give this another try. I already had found code on-line that used the TARGETIDR in the way the link provided shows. But when I added it to my custom action (as the article showed it), I got an error. But I see the comments at the link all complain about the sample being incorrect. I don't recall if I put quotes around the parameter but I'll try that. Speaking of documentation, the wizard generated installer class is passed an IDictionary. I went to the MSDN entry for IDictionary and the documentation indicates that there is an "Item" method. But when I tried to access the method the intellisense dropdown box showed no such method. When I right-clicked on the parameter in the Install method and picked "go to definition", the IDE opened up a window to show me the metadata for the interface and there was no such method. So in the end I was unable to access TARGETDIR. I was able to call the "contains" method and pass in "TARGETDIR" but the "contains" method came back with false. So at that point I just gave up on trying to pass a parameter the way the link you provided shows.


    R.D. Holland

    Saturday, March 03, 2012 3:30 PM
  • Phil,

    I tried this again being careful with the quotations marks. Apparently I do not understand how to use the IDictionary.

    I have the following code and when I run my install, I am always told there is not a "name" entry.

    [System.Security.Permissions.

    SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]

    public override void Install(IDictionary stateSaver)

    {

    System.Windows.Forms.

    MessageBox.Show("in install");

    if (stateSaver.Contains("name"))

    {

    System.Windows.Forms.

    MessageBox.Show("name is here");

    }

    else

    {

    System.Windows.Forms.

    MessageBox.Show("name is NOT here");


    R.D. Holland

    Monday, March 05, 2012 2:16 PM
  • What's in your CustomActionData property of your custom action?

    Phil Wilson

    Monday, March 05, 2012 8:14 PM
  • Phil,

    I have this in the property window:

    CustomActionData /name="[TARGETDIR]\"

    I uploaded an image shot of the property window.


    R.D. Holland

    Monday, March 05, 2012 9:07 PM
  • Phil,

    If you right-click on the image above and do a save as, you can open the file from disk and zoom in on it. It looked a lot different when I made my post (it was easily readable for me then). That allows you to see what I have entered as the custom action data.

    I don't know why it is so small now. Then again I don't know why when I hit reply that the display is such that when I am typing the "header" (your icon and name etc) is where the cursor is and I don't see text unless I either enter a lot of blank lines (to move down in the reply window) or I minimize and maximize the IDE.


    R.D. Holland

    Monday, March 05, 2012 10:39 PM
  • You should not be looking at statesaver.  You should be looking at Context.Parameters[ "name" ]


    Phil Wilson

    • Marked as answer by RD Holland Tuesday, March 06, 2012 2:03 PM
    Monday, March 05, 2012 11:42 PM
  • Thanks Phil. It's always the last place I look - or somewhere I didn't look.

    R.D. Holland

    Tuesday, March 06, 2012 2:04 PM