FAKE.IIS Add application to existing IIS site

Recently I had a task to change IIS application path in existing IIS site.
That was repetitive operation so I decided to write script for it.

I recently began to study F# and function programming so decided to try FAKE.
There is also cool explanation of FAKE here: http://blog.tamizhvendan.in/blog/2015/01/06/step-4-build-automation-using-fake/.

I have easily find IIS() function, that allows to get all the things ready at once: setup site/application pool/applications.
IIS() works in way that it will not create new site or application pool, if the same already exists.
But it will always add new version of site bindings even if the same is already exists. It makes IIS site stopped and there extra binding are to be taken care manually.

That said, I created interactive script, *.fsx file.
It is “hardcoded” and not error safe, but contains some parts, that I spent time struggling with, like figuring out where to take instance of ServerManager to create application etc.

#r @"packages/FAKE/tools/Fake.IIS.dll"
#r @"packages/FAKE/tools/FakeLib.dll"
#r @"packages/FAKE/tools/Microsoft.Web.Administration.dll"

open System
open System.Security.Principal
open Microsoft.Web
open Microsoft.Web.Administration
open Fake
open Fake.IISHelper

let siteName = "site"
let vdir = "/dir"
let path = @"C:\IIS\site\dir"

let addNewApp vdir path = 
    use mgr = new ServerManager()
    let site = mgr.Sites.[siteName]
    let app = Application vdir path site mgr
    commit mgr
This entry was posted in F# and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.