There are times that you just need to leverage the raw power that you can get from the command line. For example, if you are trying to script something or if you are on a machine that is not all tooled up with Visual Studio, Eclipse and the like and, believe it or not, there are times that it’s just a lot easier to get stuff done without an IDE in the way. Great news is that we’ve got a couple in the Windows Azure SDK called CSPack and CSRun that work wonders.
To that end, please enjoy this little tutorial on using the command line tools to create a very simple Azure package and deploying it up to the development fabric.
Before you even start you will need one of the Windows Azure SDKs installed. I’m testing this with the November 1.0 release.
First, create a directory where you will place your project. In that directory, create a directory called WebRole. At this point you will have
In the WebRole directory, place the files that you want to be deployed with your Windows Azure package. For mine, I just created a very simple HTML file that looks as follows:
<html><head><title>Quick Sample</title></head><body>This a quick sample. <br /><img alt="Sample Photo" src="photo.jpg" /></body></html>
In the root folder for your project, there are two files that you need to create. The first file is is the definition file. I called mine simple.csdef:<?xml version="1.0" encoding="utf-8"?><ServiceDefinition name="Simple" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"><WebRole name="WebRole" enableNativeCodeExecution="true"><ConfigurationSettings></ConfigurationSettings><InputEndpoints><!-- Must use port 80 for http and port 443 for https when running in the cloud --><InputEndpoint name="HttpIn" protocol="http" port="80" /></InputEndpoints></WebRole></ServiceDefinition>
The second file is the configuration file. Mine is called simple.cscfg:<?xml version="1.0"?><ServiceConfiguration serviceName="Simple" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"><Role name="WebRole"><Instances count="1"/><ConfigurationSettings></ConfigurationSettings></Role></ServiceConfiguration>
Now we are ready to start using the command line tools. The first one is called CSPack. What this tool does is create a deployment package for you.c:\Project>cspack simple.csdef /copyonlyWindows(R) Azure(TM) Packaging Tool version 18.104.22.168for Microsoft(R) .NET Framework 3.5Copyright (c) Microsoft Corporation. All rights reserved.
If you look in your directory structure now, you’ll see a new folder called simple.csx. Check it out and you’ll see that what it’s done is create a very specific folder structure ready to deploy out to the dev fabric. This is done with the /copyonly option.
The next tool is the CSRun tool. This does the actual deployment out to the dev fabric and can even, if you so choose, launch the browser for you. You need to pass it the name of the ready to deploy directory that the CSPack tool created and the name of the service configuration file.c:\Project>csrun simple.csx simple.cscfgWindows(R) Azure(TM) Desktop Execution Tool version 22.214.171.124for Microsoft(R) .NET Framework 3.5Copyright (c) Microsoft Corporation. All rights reserved.Using session id 1Created deployment(31)Started deployment(31)Deployment input endpoint HttpIn of role WebRole at http://127.0.0.1:82/
Now you are ready to run and test
To find out more about these tools read Windows Azure SDK Tools Reference