Iwanted to create Azure deploy packages through the command line. Well I wanted to create them outside Visual Studio. I started out with a with two websites in the same role with different binding endpoints. And the setup worked when i deployed from VS. In my setup, the WebRole copied files from the blob to the each website. So the initial websites were empty and the WebRole created them in the OnStart method.
I discovered one very important thing when creating packages with cspack.exe. And I want to share this with other developers, because it took me a great deal of time to find this small, but very important detail: The argument /RolePropertiesFile.
First let me show what I found out was needed to create a working package:
Here is the command:
Here WindowsAzureProject is the folder containing the Azure project and MyWebRole is the folder containing the web role added to the Azure project.
And here is the content of the file RoleProperties.txt
Here is the things i went through to get to the working result above.
I started out with the command, that could be found many places through some simple searching:
This resulted in this IIS error message: Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.
Then I did some more, well a lot more, searching and found this blog post. I added the argument /RolePropertiesFile:RolePropertoes.txt to the command and tried it out. But no luck, it did not work. The result site just gave me a new error: 403 as if no files existed on the website. The strange part was that it seemed that the WebRole did not run. In the WebRole.OnStart I had added some some remote logging. When I deployed the command line package, there were no logging, but if i deployed through VS it did do the logging. So the package was deployed, but the WebRole did not run, or excepted very early. Almost all the code was inside a try-catch-block and the exception was remote logged. But no log lines. So I’m pretty sure it did not run. Which also was the case after some more digging.
Then I tried adding the /copyOnly argument to the command. This generated a folder containing files that the emulator can use when running the WebRole. I started comparing files in this folder against the folder generated by VS and found a very interesting file: RoleModel.xml. Both files contained Properties element with a series of Property elements. The command line version of this file only had one Property element, namely TargetFrameWorkVersion that i added in the RoleProperties.txt file. The VS version of the RoleModel.xml file contained a lot more Property elements. So I added all of them to the RoleProperties.txt file, ran the command, redeployed and it worked!!
Then I started removing properties one by one, redeploying in between until i found the single property that was needed for the command line generated package to work (Yup, it took a long time to do this). And here is the result RoleProperties.txt file:
I retried the whole setup, but this time with only one website in the web role. And for some strange and unknown reason to me, it worked without the extra parameter in the RoleProperties.txt file.
So the lesson here is that using the /copyOnly argument and comparing the directory generated by the cspack.exe against VS could be very helpful.