How to set the application pool automatically during Microsoft Visual Studio 2010 web application and web service deployment

During the Visual Studio 2010 Web Application and Web Service deployment the prior setting of the application pool name is lost. The installer does not assign the correct application pool to the virtual directory, it will be assigned to the Default Application Pool.

If different .NET versions are assigned to the same application pool, the older .NET applications stop working.

To handle this problem in the VS 2010 msi file follow the steps below.

  1. Remote desktop into the web server and in the IIS manager create an application pool for your web application.
  2. Save the following program as SetAppPool.vbs to a common location in your file structure
    ' Sets the Application Pool of the Virtual Directory
    ' Usage:
    ' Right click on the Web Setup project
    ' Select Add, File
    ' Select C:\TFS\HALTeam\Other\Deployment_Tools\SetAppPool.vbs
    ' Right click on the Web Setup project
    ' Select View, Custom Actions
    ' Right click on Commit and select "Add Custom Action"
    ' Select the SetAppPool.vbs file in the Web Application Folder
    ' In the Properties window of SetAppPool.vbs enter the CustomActionData:
    '   Example: /vdir:HALGraphicUpload /appPool:HALGraphicUpload
    Option Explicit
    Dim customActionData, customActionArray, vdirName, appPool, vdirObj
    ' Read the CustomActionData of the Installer
    customActionData = Session.Property("CustomActionData")
    ' Parse the data from the CustomActionData
    customActionArray = Split(customActionData) ' Splits by the space
    vdirName = Replace(customActionArray(0), "/vdir:", "")
    appPool = Replace(customActionArray(1), "/appPool:", "")
    ' Set the Application Pool property of the Virtual Directory
    set vdirObj=GetObject("IIS://localhost/W3svc/1/Root/" & vdirName)
    vdirObj.Put "AppPoolId", appPool
    vdirObj.SetInfo

     

     

  3. Add the SetAppPool.vbs file to the Setup Project
    1. Right click the setup project
    2. Select “View”, “File System”
    3. On the left side right click the “Web Application Folder” and select “Add”, “File…”
    4. Browse to the “SetAppPool.vbs” file
  4. Add a custom action to the setup project
    1. Right click the setup project
    2. Select “View”, “Custom Actions”
    3.  Right click on “Commit” and select “Add Custom Action”
      1. Double click the “Web Application Folder”
      2. Select “SetAppPool.vbs” and click the “OK” button
    4. On the left side of the screen right click”SetAppPool.vbs” and select “Properties Window”
    5. Enter the following into the CustomActionData field
      /vdir:YOUR_VIRTUAL_DIRECTORY_NAME /appPool:YOUR_APPLICATION_POOL_NAME
      (make sure there is only one space before /appPool and there are no other spaces and quotes in the text)

Leave a comment

Your email address will not be published. Required fields are marked *