none
Custom Actions in Deployment Project - Registry Searches and Dynamic Folder Locations

    Question

  • So,

    I'm creating a deployment project, that will be installing some items to the user's computer.  However, some items will be going in pre-existing file locations, based upon a value stored in the system registry.  So, in the custom action section there is "Install", "Commit", "Rollback", and "Uninstall", however, this does not seem to afford me the opportunity to "retrieve" a registry value prior to the Install stage.  I am trying to create an installer for all our in-house Item Templates with Template Wizards which will be installed into the GAC.  However, Item and Project templates can exist in varying locations.

    So, what I would like to know is how I would create this deployment project (a simple MSI) and:
    On execution check if a Registry Field Exists:

    HKCU\Software\Microsoft\VisualStudio\10.0\UserItemTemplatesLocation

    Get that value, and then have my included "Zip" files of the item templates, install to that folder location.  Previously, I have used AdvancedInstaller (3rd party app) to handle this, but I believe I should be able to do this from a VS created Setup & Deployment project, I just don't know how.

    Thanks

    Jaeden "Sifo Dyas"al'Raec Ruiner


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Friday, September 30, 2011 11:07 PM

Answers

  • Select your setup and than open LaunchCondition Editor:

    .

    Than add registry search:

    • Marked as answer by JaedenRuiner Wednesday, October 05, 2011 6:44 PM
    Monday, October 03, 2011 10:21 PM

All replies

  • Hi JaedenRuiner,

    In next few posts I will show you how to create setup project with custom installer and get path in OnBeforeInstall method.

     

     



    • Edited by Adnan Dedic Saturday, October 01, 2011 1:59 AM
    • Proposed as answer by Neddy Ren Monday, October 03, 2011 9:32 AM
    Saturday, October 01, 2011 1:36 AM
  • Create Setup project:

     


    • Edited by Adnan Dedic Saturday, October 01, 2011 1:39 AM
    Saturday, October 01, 2011 1:39 AM
  • Add Project Output:





    Saturday, October 01, 2011 1:42 AM
  • Add Installer class in Project:

     

     

    Saturday, October 01, 2011 1:43 AM
  • Select setup project and open custom actions editor and add custom actions:

     

    Saturday, October 01, 2011 1:45 AM
  • Select application folder and project output.

     

    Saturday, October 01, 2011 1:49 AM
  • Open installer class and override OnBeforeInstall method:

     

    Saturday, October 01, 2011 1:51 AM
  • Open registry key and get key value in OnBeforeInstall method:


    • Edited by Adnan Dedic Saturday, October 01, 2011 2:01 AM
    Saturday, October 01, 2011 1:52 AM
  • Build Solution and test setup:

     

    Saturday, October 01, 2011 1:54 AM
  • Test results:

     

    Saturday, October 01, 2011 1:55 AM
  • yeap, Thank for Adnan Dedic's workthough with so many Images.

    Hi Jaeden,

    If you have any questions, please feel free to tell us.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 03, 2011 9:32 AM
  • Great explanation,

    however this is only the 1st step. 

    First is to Get the Registry Values from the system before the install process.

    Second: is to Use the value during the install.  Meaning, I have not just the "Project Output" but also other files that are added, like:

       MyTemplate.zip

    Which is created from the .vsTemplate and .cs files for the template. That file needs to be installed in the results from the above example.  Once I get the Registry Value(s) i'm looking for, the next step is to use it in the "File System on Target Machine" area of the install project.  How do I add these "Zip" files to the project in a "psuedo" folder in that view of the deployment project, so that when I complete the above process and have retrieved the "UserItemTemplate" registry value, I need to inject that value in to the "Actual" install location for this group of files.

    Thanks

    J"SD"a'RR


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Monday, October 03, 2011 5:49 PM
  • You can get path from registry in OnBeforeInstall and read value in Install method.

     

    Monday, October 03, 2011 6:36 PM
  • Okay,

    Maybe I am not being clear.

    File System Screen: Application Folder, Gobal Assembly Cache Folder, User's Desktop User's Programs Menu. 
    Added: Primary Project Output from MyTemplateWizards Project (Class Library).
    Library Contains Installer Class, and the IWizard Implementations, and a Pre-build event that modifies template files and creates template "Zip" archives.

    Now, in this Screen I need to add a "Folder" of some sort that is the folder for the template "Zip" archived files.  so Template1.zip, template2.zip that both use my MyTemplateWizards.dll for the customized item templates of visual studio.  I can create a "Sub" folder to the Application Folder, or Ican create a "Special Folder" under File System On Target Machine.  Or I can create a "Custom Folder" under File System On Target Machine.  The Custom Folder has multiple properties:

    (Name)          "Custom Folder #1"
    AlwaysCreate  False
    Condition    (null)
    DefaultLocation [TARGETDIR]
    Property           NEWPROPERTY1
    Transitive      False

    Now, under this "Custom Folder #1" I can add the Zip files to it, but the two facets that seem relevant: DefaultLocation & Property, are currently set to [TARGETDIR] and NEWPROPERTY1 respectively.  How do I set this up, so that in my OnBeforeInstall, or OnInstall "Methods", I can grab that RegValue and Assign it to this custom folder so that the Zip files are installed to that "Location".

    Thanks

    J"SD"a'RR

     


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Monday, October 03, 2011 7:36 PM
  • Ok,

    Your problem is that you cannot get source folder path (target dir) in Install or OnBeforeInstall ?

    Monday, October 03, 2011 8:14 PM
  • Neither. 

    my last post explains it perfectly.  Regardless of Install/OnBeforeInstall or the Entiry Installer class hierarchy, I have a Setup and Deployment project.  This project has a File System View that allows me to add files to the install process.  I have files that I want to go into a "CUSTOM FOLDER".  I do not know where this folder will be until I Access the registry.  This folder is NOT:

    Application Folder
    User's Desktop

    or any other system or installer folder.  Thus it must be (By definition) a "Custom Folder". 

    Those above images are my issue.  I have the CSharpItems folder and it's properties.  I have specifically added files to this folder to be included in the Install process.

    Now I have this Installer Class with Install and OnBeforeInstall.  How do I set the "TARGET" of the CSharpItems "CUstomFolder" to point to the value I retrieve from the registry.

    J"SD"a'RR


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Monday, October 03, 2011 8:33 PM
  • Now it's clear :)

    1- forget OnBeforeInstall and Install methods.

    2- this can be implemented on better way (check next few posts).


    • Edited by Adnan Dedic Monday, October 03, 2011 10:30 PM
    Monday, October 03, 2011 10:19 PM
  • Select your setup and than open LaunchCondition Editor:

    .

    Than add registry search:

    • Marked as answer by JaedenRuiner Wednesday, October 05, 2011 6:44 PM
    Monday, October 03, 2011 10:21 PM
  • Set search condition name and set properties:

    Open FileSystem editor, create special folder and set properties:

    Monday, October 03, 2011 10:23 PM
  • Yes,

    That's more what I'm looking for.  Additionally though, how would I verify that the Registry Key/Value did actually exist, and if not to set a default location for the "Custom" folder?

    thanks

    J"SD"a'RR


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Tuesday, October 04, 2011 4:35 PM
  • "That's more what I'm looking for. Additionally though, how would I verify that the Registry Key/Value did actually exist, and if not to set a default location for the "Custom" folder?"

    Can't really answer that without knowing what you want to do if that registry value does not exist.


    Phil Wilson
    Tuesday, October 04, 2011 6:04 PM
    Moderator
  • and if not to set a default location for the "Custom" folder?"

    Is that confusing? 

    If the registry value doesn't exists, I want the custom folder to point to a location of my choosing, like [TARGETDIR]\Templates or something.

    thanks

    J"SD"a'RR


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Tuesday, October 04, 2011 6:27 PM
  • Well it's it's confusing considering that the custom folder dialog already has a defaultlocation you can use, and the example screen shots above show one with [TARGETDIR] as a default, so it's not clear to me at least how much more you want that you can't figure out with a 5 minute test. 

     

     


    Phil Wilson
    Tuesday, October 04, 2011 7:27 PM
    Moderator
  • Well,

    that's my current setup, for which Adnan Dedic responded by describing the setup for the Launch Condition Registry Search and then setting the DefaultLocation of the CSharpItems custom folder to the [ITEMTEMPLATESPATH]. 

    this tells me that when the MSI is executed to start the installation, if the registry key is found [ITEMTEMPLATESPATH] will be set to the value in the registry value.  However, if that registry value (or parent key) does not exist, what is that [ITEMTEMPLATESPATH] set to?  Can I set it to [TARGETDIR] or something to that effect, or would I be setting the CSharpItems.DefaultLocation to [TARGETDIR]?

    Do I need to do this evaluation in the Installer class in one of the BeforeInstall or Install mehods?  Basically, I know from using something similar in the thrid party Advanced Installer application, that it isn't as simple as grabbing the registry value in the search, because in the past with the Adv Installler, if the registry key/value didn't exist the install failed.  I do not what this to happen, I want the registry value to populate the location of that folder if and ONLY if the key/value exists.  Otherwise I want that Folder to point to [TARGETDIR]\Templates

    Thanks

    J"SD"a'RR


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Tuesday, October 04, 2011 9:10 PM
  • Hi JaedenRuiner,

    If items templates path was not retrieved from registry than CSharpItems will be created in [TARGETDIR].

     

    Default path:

     

    Path from registry:

     

    • Edited by Adnan Dedic Tuesday, October 04, 2011 10:45 PM
    Tuesday, October 04, 2011 10:41 PM
  • Custom folder properties:
    Tuesday, October 04, 2011 10:42 PM
  • Ah,

    so the default location for a CustomFolder whose property is not assigned (ie: ITEMTEMPLATESPATH) will revert to [TARGETDIR]. 

    Is there a way to set these properties from within the Install() and OnBeforeInstall() methods of the installer class?

    THanks

    Jaeden "Sifo Dyas" al'Raec Ruiner


    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Wednesday, October 05, 2011 6:44 PM
  • I think you can access Session object from installer.cs and change property.

    On my PC I have installed only Visual Studio 2005 and .net 2.0 and I cannot write example but I will try to download Visual Studio 2010 and if I found some solution I will post example.

    Wednesday, October 05, 2011 6:51 PM
  • "Is there a way to set these properties from within the Install() and OnBeforeInstall() methods of the installer class?"

    No. All custom actions (even those with names like "before install") are called after all the files have been installed, so it's too late to change destinations.

    The default location for a custom folder is whatever you want it to be, based on the standard folder properties listed here;

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

     


    Phil Wilson
    Wednesday, October 05, 2011 7:51 PM
    Moderator