Sunday, September 25, 2011

How To: Look inside the Service Package file

If you ever wanted to see what’s inside a published .cspkg file: here is a small guide how to achieve this…

First there is to say that a .cspkg-file is only a ZIP file with extensions changed. But the contents are encrypted. But there is a way to create unencrypted Service Packages:

  1. Close Visual Studio
  2. Shut down Windows Azure Compute Emulator
  3. Go to Control Panel > System and Maintenance > System
  4. Click on “Advanced Settings” in the pane on the left
  5. Switch to the “Advanced” tab and click on the “Environment Variables” Button.
    The “Environment Variables” dialog appears.
  6. Check for a System Variable named _CSPACK_FORCE_NOENCRYPT_
    If there is no such variable, create it.
  7. Set the value of the _CSPACK_FORCE_NOENCRYPT_ variable to “true”
    image_thumb_4
  8. Start Visual Studio again and publish a Cloud Service Project.

Note: When publishing without encryption, Visual Studio warns you with the following message in the output window
CloudServices44 : Forcing creation of unencrypted package...

To sneak inside the package do the following steps:

  1. Rename your <cloudservice>.cspkg file to <cloudservice>.zip
  2. Unpack that .zip folder
  3. Inside the uncompressed folder there is a file named after your web role <WebRole><Guid>.cssx
  4. Rename the .cssx file to .zip
  5. Since you performed the steps before, this .zip file is unencrypted now. Unzip it.
  6. Find the content of your package in the “sitesroot” folder.

Caution: Although either encrypted and unencrypted packages can be deployed to the cloud, it’s highly recommended to only use encrypted packages for security issues.

Issue: change physical path of site named “Web”

In earlier posts I showed how to use multiple sites within a single WebRole. This required to use the physicalDirectory attribute within the ServiceDefinition file. If you tried to use this attribute you might have run into this issue:

The default site in a WebRole is named “Web”. When you set the physicalDirectory attribute to point to any location – no change will happen.

It seems as if a site named “Web” ignores the physicalDirectory attribute.

But if you change the name to any other name: the physicalDirectory attribute will be used!

For further explanation have a look at the following xml snippets from the .csdef file:

<Site name="Web">
  <Bindings>
    <Binding name="Endpoint1" endpointName="Endpoint1" />
  </Bindings>
</Site>
This will use the default content.
<Site name="Web" physicalDirectory="C:\Code\WebApplication2">
  <Bindings>
    <Binding name="Endpoint1" endpointName="Endpoint1" />
  </Bindings>
</Site>
This will still use the default content.
<Site name="Web1" physicalDirectory="C:\Code\WebApplication2">
  <Bindings>
    <Binding name="Endpoint1" endpointName="Endpoint1" />
  </Bindings>
</Site>
This will use content from WebApplication2.