Adding Files to your Windows Azure Service Package

When using the Windows Azure Tools for Visual Studio, there are two times that you end up creating a Windows Azure Service Package:

  1. When you build and run on the Development Fabric -- this is a folder based package, extension is csx.  This is used by the Development Fabric.
  2. When you use the "Publish" feature -- this creates a .cspkg file which is a zipped and encrypted version of the csx built in (1).  This is what you upload to the Cloud.

This post explains how this process works so that you can have better control over what files end up in the package. 

The first thing to know is that in both cases above, the way the contents of the package is created are the same.  The difference is that in case 2, the package is zipped and encrypted.

Web Role

The way the Web Role copies files to the Service Package is by using the internal ASP.Net _CopyWebApplication build target.  This build target copies the build outputs and content files.

In other words, it doesn't copy all of the files in your project to the Service Package.  It has to either be a build output or a content file. 

If you want an your file to be copied, you can add it to the project:

image

and set the Build Action from "None":

image

To "Content". 

image

This marks the file as "Content" and will copy the file to your Service package (both when debugging in the DevFabric and "Publish" to the cspkg).

The other option you have is to keep the Build Action as "None" but set "Copy to Output Directory" to "Copy if Newer" (or "Copy Always").  The difference is that when you set the Build Action to "Content", the file will show up in the root of the Web Role folder, whereas when you set the file to Copy to the Output Directory, it will show up in the bin directory along side your build output.

image

One of the side effects of using the Web Application build action is that linked files are not supported.  We're working with the ASP.Net team to get this fixed in the future.

Worker Role

A Worker Role does not use the Web Application target that I referred to above and the only option to have extra files copied to the Service Package is to keep the Build Action set to None and set Copy to Output Directory to "Copy if newer".

Assemblies

For assemblies that you need to have copied to the output directory, you can always add a reference to that assembly, even if you don't need it directly from your Web or Worker roles.  The reference has a property "Copy Local" which defaults to true.

One exception is if the referenced file is in the GAC and you'll have to set "Copy Local" to true manually.

Comments

  • Anonymous
    January 28, 2009
    Jim has posted about how you can include additional files in your package when packaging for the Development

  • Anonymous
    March 20, 2009
    One of the cool new features in the Windows Azure Mix 09 CTP is the ability to run your Web and/or Worker

  • Anonymous
    April 09, 2009
    This is part 1 in this series where I am building an Azure shopping cart application from the ground

  • Anonymous
    May 19, 2009
    we have a plans of using the SQLite as a stroage for the cloud aplication which we are going to develop. I have added the SQLite DB file to the package using the approach, given above. Used System.Data.SQLite (ADO.NET Provider) assembly in my code to access the SQLite DB. I have the ran the application in local fabric, working fine. After I have deployed it on the cloud , stopped working. Its throwing the below exception [System.ServiceModel.FaultException<System.ServiceModel.ExceptionDetail>] = {"Could not load file or assembly 'System.Data.SQLite, Version=1.0.61.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The system cannot find the file specified."} I have added the same version of SQLite dll to the web role references . Seems to be while creating the package(Publish option) the SQLite DLL has not been added.  My thought on this is while creating the package it does check what are all the references been added and should copy all those dlls to the package? Is there any restriction that we shouldnt use any Third party assemblies such as SQLite, etc?

  • Anonymous
    May 21, 2009
    It looks like the assembly you need isn't being copied into the package -- make sure you set the "Copy Local" property for that assembly to true. Also see this post: http://blogs.msdn.com/jnak/archive/2009/04/16/digging-in-to-the-windows-azure-service-package.aspx It will tell you how you can check the contents of your service package to see if the dll is in there. What location are you going to store your data?

  • Anonymous
    June 29, 2010
    ...this doesn't always work.  I've created a clickonce package and have included all the file in the ASP.NET web project to deploy.  I've set both of the settings you lay out here and it still doesn't end up in the actual deployment directory. Just sayin'...  and i'm still working on a solution.

  • Anonymous
    July 06, 2010
    Just to note... - this applies only to Windows Azure service packages and not click once packages.

  • Anonymous
    September 01, 2010
    Hi, About the Copy to Output Directory, I want to include several directories with files in my project because I need to run an existing native application, but in Visual Studio I could not find a way to apply recursively the property Copy to Output Directory to Always Copy for all files under a directory, I could do it file by file, that in my case is not acceptable (It may be hundreds). So how can I do that? or why Visual Studio does not support this? I ended using the manual cspack.exe utility by hand, but I am surprised I could not do this with Visual Studio. Regards

  • Anonymous
    May 16, 2012
    Many thanks. BuildAction = 'content' solved my problem of including pdf files in the package.

  • Anonymous
    March 12, 2013
    Nice. Change "Content" to "None" avoid double copying.

  • Anonymous
    February 27, 2014
    What about copying files next to your package. Just like the .cscfg files? Is this possible as well?