When using the Windows Azure Tools for Visual Studio, there are two times that you end up creating a Windows Azure Service Package:
- 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.
- 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.
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:
and set the Build Action from “None”:
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.
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.
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”.
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.