How to Handle Web Application IIS settings.

Oct 22, 2010 at 5:06 PM

On my web application, I have it setup to work with the local Internet Information Services (IIS) instead of the development IIS server.  This is done because of the differences in the way they handle security.  I have 3 branches for my applicaiton, Main, Development and Release.  Traditionally I have three websites on my development computer to house the three websites.  I have used http://localhost:8081, http://localhost:8082, and http://localhost:8083. The issue I am running into is that when I make a change to my project and merge it, the IIS settings are being overwritten.  These settings are kept in the csproj file in the IISUrl node.  ("<IISUrl>http://localhost:8081/</IISUrl>").  Is there a way to keep the branches from overwriting this setting?  Or is there a mechanism like Web.Config Transformation that works with the project files?


Mar 3, 2011 at 11:53 AM
Edited Mar 3, 2011 at 11:55 AM

We have this issue too. What we do is only use one virtual directory and keep changing its settings in IIS to point to the branch we are using at the time. Generally though this is a PITA and it would be great if MS could come up with a better solution.

Here is a .bat file that can be used to do this easily, I'm sure this could be altered to do the site's location as well (remember to run as Administrator):

@echo off

echo .
echo 1: Development
echo 2: Release Phase 1
echo 3: MAIN
echo Q: Quit

set INPUT=
set /P INPUT=Select branch: %=%

if "%INPUT%"=="1" goto Development
if "%INPUT%"=="2" goto Release1
if "%INPUT%"=="3" goto Main
if "%INPUT%"=="Q" exit
if "%INPUT%"=="q" exit

Echo Input Error (%INPUT%)
goto Input

echo Setting up Development...
%WINDIR%\System32\inetsrv\appcmd set VDIR /"Default Web Site/MySite/" /physicalPath:"C:\Users\martin.brown\Documents\Visual Studio 2010\Projects\MySite\Development\Web"
goto end

echo Setting up Release Phase 1...
%WINDIR%\System32\inetsrv\appcmd set VDIR /"Default Web Site/MySite/" /physicalPath:"C:\Users\martin.brown\Documents\Visual Studio 2010\Projects\MySite\Release\Phase1\Web"
goto end

echo Setting up Release Main...
%WINDIR%\System32\inetsrv\appcmd set VDIR /"Default Web Site/MySite/" /physicalPath:"C:\Users\martin.brown\Documents\Visual Studio 2010\Projects\MySite\Main\Web"

goto input

May 11, 2011 at 5:54 PM

Thanks for the VDIR redirect script fragment mqbrown. I was aware of this concept but hadn't researched how to implement it. Very handy for quick redirect of one or more services.

1. Microsoft Web Deployment Projects support the concept of build-specific config file sections. You build for desired target environment and you get related config files as part of the build process. This has benefits and drawbacks. I personally don't like this approach because as a tester I want one build that can be deployed anywhere without rebuilding or using a different build with chance of unintended differences (hence requiring some re-testing to verify each build variation is functionally equivalent).

Another option is to check-in web.config and other environment-specific settings for a default dev environment deployment, then use a script to replace default environment settings with target environment values. Default deployment needs no changes, and other environments use a standard post-deployment configuration script based on a "single source of truth" XML/spreadsheet of environment-specific values (which is also checked in). This is the approach my team is taking.

For post-deployment configuration there are several tools that may come in handy:

  1. regex (regular expressions) are built into PowerShell (.NET regex syntax), Perl, and other script languages. A set of regex expressions read from an XML file (which PowerShell and some other scripts can easily parse) could be used to transform default environment settings to match target environment.
  2. XMLPreProcess is a codeplex project that stores environment-specific variables in an XML file then alters Web.config or other XML files depending on -env parameter passed.

I have a custom script that implements combination functionality of the above public tools, but I haven't adapted it to my team's current projects because I'm looking for more publically supported solution for this common requirement.

I'm sure there are more (possibly better tools) publicly available.
ALL: If you know of other tools and solutions please reply with name and your experience (good, bad, or haven't tried it)!