Setup and deployment project + Environment variable

Sorry for the not-so-helpful subject line.

I have a c# application for which I am trying to create an installer. I am using the 'Setup Project' template under 'Setup and Deployment' for achieving this.

I have added two files a.exe and b.xml under Application Folder. I want to set the default location of the Application Folder as some environment variable say 'DEF_DIR'. How do I achieve this

I tried all these options:
$DEF_DIR
%DEF_DIR%
ENV(DEF_DIR)
$ENV(DEF_DIR)

No luck so far. Can someone please help


Answer this question

Setup and deployment project + Environment variable

  • boates

    Mubshir, I will try out your solution. Thanks for that.

  • johnedw

    Hi J Andrews,

    Go to the following link...

    http://support.microsoft.com/Default.aspx scid=kb;en-us;829145&spid=8291&sid=89

    Hope this help.



  • savoiu

    HI,

    I understand what actuly you want. Solution is very simple...

    As you know that setup project allows to search the registery values by creating a launch condition and then you can also use searched value as Default Location Path for the TARGETDIR.

    If you dont know how see this artical ...
    http://support.microsoft.com/default.aspx scid=kb;en-us;827026

    Your environment variable also exist in registery. For example you  create a user environment variable name AppPath the you can see it in the registery.

    (How  Just type regedit in the  run text box in start menu registery editor will be open just goto HKEY_CURRENT_USER\Environment there you can see your variable name AppPath )

    So, in you setup project simply search  registery key of your environment variable by creating a launch condtion and then set its value to TARGETDIR's DefaultLocation . More if you want user to be not able to change this location the remove the Installation Folder from user interface editor.

    Hope this help.



  • twbrandt

    No, it works because TEMP is an Environment variable and the Windows Installer way to get the value of an environment variable is:

    [%var]

    as documented here, 4th bullet:

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/msi/setup/formatted.asp

    And the Windows Installer property name for the temp folder is TempFolder, not TEMP, so that would be [TempFolder]



  • xiaobinker

    I don't know of a way to do it inherently with setup projects.

    THere might be a way to do it in Windows Installer, and if we were able to find a way you'd have to use a post-build step to open and modify the built installer.

    Another way might be how you launch the installer... if you do it from a command line you can do:

    msiexec /i mysetup.msi TARGETDIR=%ENVVAR%



  • Mrhaboobi

    David, I want to make the default installation directory point to some environment variable. Your solution works on the other side - the end user side. If the user wants to set the installation directory to an environment variable value, your solution words perfectly fine.

    Phil, it works because 'TEMP' is a standard directory, if I may call that. Just like TARGETDIR always points to C:\program files\<company name>\<application>, TEMP will point to your temporary directory. I am talking about a directory which is not a standard one. If this directory is available to me as MY_SPECIAL_DIR environment variable, can I use this instead of "TEMP" in your example I don't think so.

    Actually, I think my requirement itself is flawed. I don't think it makes sense to say that the user will define an environment variable and my application would be installed there. Hmm.. if I think back, I think I had been stupid to expect that! Well, lesson learnt.

    Thanks everybody for replying.

  • Zelalem

    Phil,

    I was wrong. You were right, I can use any environment variable. I tried it out and it works. Thanks a lot for giving me the right solution.

    J


  • Amitkumar

    Try setting the DefaultLocation of the folder like this:

    [%TEMP]

    I just tried this, and sure enough it shows up with my temp location in the installation folder



  • Gary Smith

    Hi Mubshir,

    Thanks for the reply. But, it is not what I am looking for.

    I want to use the value of an environment variable in the properties of 'Application Folder' in my Setup project. I googled quite a bit, but couldn't find a solution.

    Thanks for taking time to reply to my question,
    J

  • Setup and deployment project + Environment variable