Thursday, May 5, 2011

Virtual Directory in Web Setup Project

I have a web setup project which by default shows the virtual directory in the textbox installer screen. I wish that the virtual directory name cannot be edited by the user and always defaults to the one I have setup in my msi. How can this be achieved?

From stackoverflow
  • Switch to Wix and use their Web Extensions

    chugh97 : I am looking at the websetup project as I am not interested in open source as org does not allow it.
    Shay Erlichmen : Wix is written & maintain by Microsoft, it was suppose to be part of Visual Studio 10. Many originations (Incl. the Office 2007 setup) are using Wix without any problem.
  • Select your setup project, View > Editors > User Interface, select the Installation Address dialogs, and delete them.

    EDIT:

    As Shay points out, users can override the default install location from the command line. To override this, you should set the TARGETDIR property in your InstallExecuteSequence. Unfortunately, you cannot change this sequence from Visual Studio, you have to use Orca:

    1. Build your Setup project.
    2. Open the MSI file from Orca.
    3. Create a new custom action of Type 51 (set property) with Source "TARGETDIR" (without quotes), Target of your destination folder, and a unique name for Action (the convention is to use a GUID with initial underscore).
    4. Create a new row in the InstallExecuteSequence with your unique name for Action, "NOT Installed" for Condition, and a sequence number before the use of TARGETDIR (750 was the first use in the sample I made, so I used a sequence of 555).
    Shay Erlichmen : deleting from the UI would still allow the user to change the setup dir via command line.
  • Org does not allow open source, or GPL open source.

    Solutions: * edit the custom action (right click>view>custom action) to fix the virtual directory and path Change the customactiondata:

    /targetdir="[TARGETDIR]\" /connectionstring="[CONNECTIONSTRING]" /targetvdir="[TARGETVDIR]" /targetsite="[TARGETSITE]"
    

    To:

      /targetdir="[TARGETDIR]\" /connectionstring="[CONNECTIONSTRING]" /targetvdir="FIXED_NAME" /targetsite="[TARGETSITE]"
    

    You might just delete the Installation Address from user interface, and setup a component that passes information to the custom install

    • Write a wrapper over msbuild with msbuildtasks
  • In order to get the Virtual Directory using Context.Parameters

    1. Add a Custom Action to Install node (use this url if you want to know how to add custom actions)
    2. Right Click on the custom action and select properties window.
    3. For CustomActionsData property set /targetvdir="[TARGETVDIR]".
    4. Now in your installer class you can get the virtual dir name by Context.Parameters["targetvdir"]. Hope this helped you :)
  • If you don't want the user to change the virtual directory you can simply remove the "Installation Address" dialog from the User Interface.

    1. Right Click installer project and select "User Interface".
    2. Expand the "Start" node.
    3. Right click on "Installation Address".
    4. Select "Delete"

    If you want different parameters for the Web site, virtual directory, application pool that is normally selected by the installation address dialog you can override with a custom action as others have described.

    However, in my experience custom actions do not help with setting defaults that the user can change because they execute After the dialogs that ask for user input.

    The easiest way to set some defaults that the user can override if necessary in a dialog is to do the following.

    1. Remove the Welcome Page.
    2. Add a Textboxes dialog (for example "Textboxes (A)")
    3. Change Visible properties for all the textboxes to false so no textboxes are shown.
    4. Change the BannerBitmap and BodyText property so it looks somewhat like a welcome page.
    5. Set the necessary properties you want to override in the "Edit*<n>Property" and set the default value in the "Edit<n>*Value".

    The most useful properties (IMHO) are.

    TARGETDIR - Where the files are to be copied.
    TARGETVDIR - The Virtual Directory to be created in the specified site.
    TARGETAPPPOOL - The application pool to use (NOTE: This must exist, it won't be created)
    TARGETSITE - The website where the virtual directory is to be created (NOTE: This is the metabase value for the web site... For example: "/LM/W3svc/2". Also note that the site must exist).

    There is a full list of properties for the installer can be found here.

    If you really want better control over the IIS setup I would suggest changing your project to a standard Windows Installer project and creating custom Install actions so that you can programatically create AppPools. A good place to start to understand programmaticly creating these things is here.

    The biggest reason for doing it this way is that custom actions run after prompting but the app pool and web sites must be created before the installer can prompt.

    ladenedge : That note about TARGETSITE being a metabase value was a lifesaver - thank you!
    Markive : Yep I've been searching for hours for TARGETSITE! Cheers!
  • Sounds good in theory but near as I can tell, doesn't work, at least not for setting AppPool. I have a custom action to set the apppool (which by the way works fine when the installer is built with VS2005) in my vs2008 web setup project.

    DirectoryEntry IISVdir = new DirectoryEntry(String.Format("IIS://{0}{1}/{2}", strServer, strRootSubPath, Vdir));
    IISVdir.Properties["AppPoolId"].Value = appPool;
    IISVdir.CommitChanges();
    

    The installer runs with no dialog (removed the installation address UI node) but the AppPool set on the virtual directory ends up being DefaultAppPool.

    Other custom actions in my helper class do run and work.

    So there must be some other magic incantations needed.

    Thanks.

    Tim C : I just had a similar problem. I could only solve it by getting by custom action to run at the Commit stage, instead of the Install stage.

1 comments:

Pablex said...

How solve that? I need create another targetSite, example "Default Web Site example", and install my Web in this Site...I sent to installer class all values and create new Site, virtual directory and another things, but the site always is installed in "Default Web Site" and "Default Web Site example"

Post a Comment