I want to write a small installer app that installs a web site and creates IIS virtual directories. The app should run on Windows XP/Server 2003 (IIS 6) as well as on Vista/2008 (IIS 7).
The problem is: for IIS 6 we create virt dirs by calling WMI/Metabase API, for IIS 7 there is a much better API: Microsoft.Web.Administration, but its assembly is available only on IIS 7 systems.
Naive approach:
...
if (OperatingSystem == old)
{
call metabase API...
}
else
{
call Microsoft.Web.Administration...
}
...
Nice, isn't it? But how can I make sure that this does not crash on a old system just while trying to load the Microsoft.Web.Administration DLL? Or is an assembly just loaded, when it is first used? When a method that is calling into the assembly is first used?
I guess, testing does not help without some determinism being guaranteed by CLR/.NET spec.
I am really looking forward to hearing your experiences, hints or solutions for this topic. I have not found anything remotely usable on the web so far.