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