Bug: Application Creation via AppCmd.exe
I was trying to find the syntax in AppCmd.exe to convert an existing virtual directory say - myVdir to be an application.
Obviously, the first step is to create the virtual directory. (I know I can do both with appcmd add app bla bla and create the associated vdir). but I was looking for the way to do it as the IIS Manager, right mouse - Convert to Application)
Step 1 - create the vdir
appcmd add vdir /app.name:"default web site/" /path:/myVdir /physicalPath:c:\temp\vdir
Output:
VDIR Object "default web site/myVdir" added
Then, I spent sometime looking on how to 'covert' myVdir to an application itself, in other words make the <virtualDirectory> itself as "/" or root vdir which indicates that it is an application staring point in IIS 7.0. But I got no luck :( maybe my mind got stuck after playing with AppCmd.exe for 3hrs. I can't use "appcmd set vdir" as there's no options for application, and I can't apply "appcmd set app" because it is not an application yet, it is just a Vdir using the root application.
Anyway, so after awhile I decided to use "appcmd add app" and hoping that IIS detects that the vdir already defined, and it will just reconfigure it as an application. So,
Step 2 - create the app
appcmd add app /site.name:"default web site" /path:/myVdir /physicalpath:c:\temp\vdir
Output:
APP Object "default web site/myVdir" added
VDIR Object "default web site/myVdir/" added
Voila!!! I was so happy, I thought it works as I was expecting duplicate element error :) but no error msgs. So I fired up IIS Manager to check! Zzz... I can't no longer expand the "default web site", and got an error msgs saying "An item with the same key has already been added". Sigh! so the configuration store accepted the duplicate entry and now it complaints! Argghhh!!!
Now, to fix this! again I found something interest. You can do it via UI in Vista, but not W2k8 Beta 3. For vista, just click OK to ignore the error, then View Applications - right click on myVdir, and then click Remove. Now, if you try the same steps in W2k8, after the delete confirmation dialog box, you got back the "An item bla bla ........." error msgs again :) To fix this for W2k8, go to applicationHost.config file and manually remove the duplicate entry. And I conclude this as a validation bug of appcmd when trying to manipulate the configuration store.
Mm....now! I'm back at where I started. so is it possible to 'Convert to Application' for existing vdir via AppCmd.exe ???
Updated - 170707
I should have mentioned that W2k8 I'm using is from April CTP, you won't get the UI error in June CTP.
Also, according to Microsoft - it is acceptable to have same /alias inside the different application. In my case, the vdir of the default web site/ root application will never get reference as the /myVdir application's vdir definition kicks in first. Mm.... I still don't like the idea, why it accept both when only 1 is technically working?
Anyway, for my question - no way to 'covert to application' from appcmd.exe in 1 step :)
You can however, first delete the vdir, then create the app..... two steps at least.