It’s a pain that every time that I want to start a Windows Azure application locally, I must first start Visual Studio and start the debugger. In this post I will describe how to start an application in Windows Azure Compute Emulator without using Visual Studio debugger. This will work for an application that is a Web Role or Worker Role. There are multiple ways to do this, but I believe this may be the simplest.
In this post I will start from the very begginning of creating a new Windows Azure Cloud Service project and creating a default ASP.NET MVC 4 website. If you want skip all the setup and get to the meat of csrun, then scroll to the bottom of the post.
- Visual Studio 2012
- Windows Azure SDK
Let’s get started.
First open Visual Studio 2012 and created an Windows Azure Cloud Service project . Then select ASP.NET MVC 4 Web Role.
I changed the name fo the ASP.NET MVC 4 website to “MyWebsite”
Since we want this to be a working project, select “Internet Application”
Once you finished the wizard there should be 2 projects created within a solution. For me, my two projects are “AzureSample” and “MyWebsite”
That’s all we need to do to get the project up and running. Before we run this application its import to notice that in the AzureSample directory there is no directory called “csx”. The “csx” directory is need to run the application without using Visual Studio and the debugger. It’s somewhat a catch-22 situation in that we need to debug the application once to create the “csx” directory.
If we run (F5) the application through Visual Studio, Visual Studio will package and deploy the website to Window Azure Emulator. Once this is completed you should notice that the “csx” directory has been created.
Also during this time Visual Studio has started the Windows Azure Emulator. The status of Azure Emulator will be displayed if you hover your mouse over the Windows Azure Emulator Icon in the System Tray.
If you right click the Azure Emulator Icon, you can select “Show Compute Emulator UI”. This will open the Windows Azure Compute Emulator UI
In the Windows Azure Compute Emulator, you can see that our Application was been installed and is running at 127.0.0.1:81
By using your browser and the URI identified in the Azure Compute Emulator, you should be able to navigate to the page.
Stop the debugger in Visual Studio. This should kill the application running in the Windows Azure Emulator.
All we did here was confirm that the website worked. Now that the “cts” directory is created and we are confident the website works, lets start the website without using Visual Studio and the debugger.
For presentation purposes I’ve closed Visual Studio.
Now starts the Windows Azure Command Prompt. I believe this should be run in administrator mode.
In the console navigate to the directory that contains the AzureSample. For me, the path is C:\Projects\Samples\Azure\AzureSample\AzureSample
Once you have navigated to the directory, run “dir” to get a directory listing. In the results there should be a directory call “csx” and a file with the extension of “local.cscfg”. This is the information we need to start the application in Windows Azure Emulator
Now in the console we will run csrun with 2 parameters. The first parameter will identify the location of the package. The second parameter will identify the configuration file to use. For this example the package is located in “csx\debug” and the configuration file is called “serviceConfiguration.Local.cscfg”.
In the console execute csrun with the two parameters. For me the command is “csrun csx\debug ServiceConfiguration.local.cscfg”
This will install the application into Window Azure Compute Emulator. The results of the command identifies that the website will be running at 127.0.0.1:81.
We can see that in the Windows Azure Compute Emulator that the website is running.
Now in your browser of choice navigate to 127.0.0.1:81 and the browser should display your page.
I hope this helped.