Recently, i did a webcast on this topic and we are running WebCamps on WebMatrix as well which will be covering this part. Hence the premise of this post is to provide steps to deploy the application you developed on WebMatrix as a Windows Azure Hosted service.
Before i detail the steps, here are the links i referred to and those that will add more value
To run the demo source code and set up your environment for WebMatrix to Azure migration, you will need
Below are the steps you can follow for migration
STEP 1 : Create your WebMatrix application as you normally do
1. Fire up WebMatrix and Site From Template and lets choose Photo Gallery for this demo
2. This will generate the code stubs that gives a readymade sample ready to execute. Click on Run and choose browser of your choice.You could login /register and add a photo gallery of your choice and modify this template however you choose. You can also check the Files tab on the bottom left and take a look at the code. For reference on code using Razor syntax and creating an WebMatrix application, please read from here : http://bit.ly/pIgcno
3. You can click on Top left option “Publish” and below wizard will pop up.Here you can ftp or web deploy to any server of your choice. There is option “import publish settings” in case you want have a file available by your service hoster. But publishing to Azure Platform is not as straight forward as below.
STEP2 : Now for migrating this WebMatrix application as an hosted service in Azure
Windows Azure will take 2 files to make sense of the application
1. Scrubbing the WebMatrix application
Go to physical folder location & Add assemblies
2. Targeting the .NET framework 4.0 in Windows Azure
Azure that the .NET runtime which is being targeted is 4.0 since WebMatrix runs under 4.0 context. Create a properties.txt file with single line of code “TargetFrameWorkVersion=v4.0” and place it outside the PhotoGallery folder(i.e - outside the base WebMatrix folder).
3. Creating Service Definition File
For Windows Azure to run WebMatrix, it will look for the ServiceDefinition File, which will tell which folder( called Role ) that it needs to Web Deploy. In this example, we will deploy the application as a Web role and say that IIS should listen at port 80 for the same.
Hence, create “ServiceDefinition.csdef” and put in the below code:
4. Creating the Configuration file
Open the Windows Azure Command prompt and we can package the application to run under cloud simulation. While doing this we can generate the the ServiceConfiguration file as well using “generateConfigurationFile” helper. Take a look at the syntax below. We are calling the “cspack” command to package the application and passing the following
5. Deploying the application on the Development Emulator
Step 4 needs to be done to get the output unzipped package
Next we need to run the package like “csrun HelloRazor.csx ServiceConfiguration.cscfg /launchBrowser” as shown below and the browser will be launched as shown.
6.Create the Deployable package to Azure Data Centre as a hosted Service
Finally, once you have tested locally and ready to push it onto the cloud, you can run the cspack command with below parameters
You will get a cspkg file generated at the same folder.
7. Upload the Deployable package to Azure Data Centre as a hosted Service
Once the status of the role become ready you can browse to the URL and you will see your WebMatrix application running as an hosted Service on Azure virtual machine!
Hope this post was useful and some of the key downloads are below: