Now lets jump right in and write some code and get this thing in the “cloud”. This time File –> New –> Project presents us with the Windows Azure Project template and the ‘Cloud’ heading.
Once you select that, you will be prompted to select a “Role”. In this example, we’ll select the ASP.NET MVC 3 Web Role. You will most likely want to change the default name by hovering over the newly added role and selecting the edit button as this will become your project name.
We’ll select an empty project template using the Razor view engine to work with.
When we’re all done we’ll have our “AzureMVCApp” project along with some Azure specific items inside our solution.
We’ll skip over the adding of controllers and views to the MVC application. For simplicity’s sake, I’ve added a controller and a view that simply displays some text that was defined in the controller action.
Before we go any further we should just verify that code works. You will notice that the Azure Deployment project is set as the StartUp project. So if we just hit F5, we will see a message box pop up telling us that we’ll be running inside the Azure Debugging Environment that was one of the components installed in part 1 (incidentally you can always change the StartUp project or right click and select debug from the other included projects to debug them outside of the Azure Emulator).
The first time you start a Windows Azure project, it will look for a local SQL Express installation in which to provision a database for the Storage Emulator. If SQL Express is installed it will automatically create a new database. If not you’ll see an error like this:
Windows Azure Tools: Failed to initialize the Development Storage service. Unable to start Development Storage. Failed to start Development Storage: the SQL Server instance ‘localhost\SQLExpress’ could not be found. Please configure the SQL Server instance for Development Storage using the ‘DSInit’ utility in the Windows Azure SDK.
Using the DSInit tool, you can create the database manually and point to an installation other than one on your local machine.
After this completes, we should see a browser window open displaying our text output. In the next post, we will deploy to Azure.