Why is appcmd.exe unlock config not working on Azure emulator? Why is appcmd.exe unlock config not working on Azure emulator? azure azure

Why is appcmd.exe unlock config not working on Azure emulator?


It turns out that when the emulator launches the startup task, it has already set the APPCMD variable. Moreover, it sets it not just to refer to the AppCmd.exe, it also includes a command line switch that points to the right configuration file:

"C:\Program Files\IIS Express\appcmd.exe" /apphostconfig:"C:\Users\Ian\AppData\Local\dftmp\Resources\1217ef49-a59a-4e18-8ebc-27d06a78cbd5\temp\temp\RoleTemp\applicationHost.config"

So if the startup script just uses %APPCMD% without first attempting to set it, it will apply to the correct instance. My script was not working because it made its own decision about where AppCmd.exe was located, and would end up modifying global settings for either IIS or IIS Express, neither of which seem to have any impact on the instance of IIS that the Azure Emulator hosts. (I'm guessing that this is a recent change in behaviour, possibly relating to the new feature in Azure SDK 2.1 that enables non-elevated development.)

The thing that worries me about this is that I can't find any documentation that mentions this pre-defined APPCMD variable. I only discovered it by adding the following to my startup command script:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe "gci env: | format-list"  > c:\temp\env.log

I added that temporarily and ran the web role, and it provided a complete dump of all environment variables. Looking through that list, the APPCMD variable is the only one that contains the information required to target the correct configuration. But the documentation for startup tasks seems to recommend pointing directly at the IIS copy of AppCmd.exe - the Use AppCmd.exe to Configure IIS at Startup article just hardcodes the path. I guess that would work if I enabled the use of full IIS in the emulator, but I don't really want to do that.

So although this solution works (and appears to be the only viable solution, given what's in the startup task's environment) it makes me nervous because it's an undocumented feature. So be careful if you've stumbled upon this answer - it might not be reliable.