Friday, August 22, 2008

Web Application Projects - Publish Options

In Web Application Projects (WAPs) we have the following Publish Dialog box.



It has the target location text box which takes destination to be HTTP (which uses Front Page Server Extensions (FPSE) behind the scenes), FTP, or File System.

Publish settings also allows you to have a clean install or just incremental updates.  Although what is interesting to notice are the various Copy options.  Let us try to understand what these mean:

  • Only files needed to run this application - In a WAP we usually have a Project file, User File,  Bin folder, Obj Folder, ASP.NET pages, User Controls, WCF and Web Services etc.  ASP.NET Pages and other similar files have two additional artifacts in a WAP project as shown below:

image When you build the WAP project the sources from both the .aspx.cs as well as .aspx.designer.cs files are taken and compiled into the intermediate output folder (i.e. OBJ folder) and then finally moved to the (BIN folder)...   

You do not really need the Project Files (.csproj/.vbproj); User File (.user)  to run your web neither do you need any of the code behind or designer files as they are compiled into your Bin folder.  At the same time you also do not need the OBJ folder as that is just the intermediate folder VS uses before produces the final output in the BIN folder.  Based on this rationale VS removes all those files from the publishing process and only publishes the files which are required to run your application (which are your .aspx and other similar markup files), your referenced DLLs and your bin folder.

  • All Project Files - Based on the above discussion it is apparent that your code behind and designer files are part of your project, so are your .user and .csproj/.vbproj...  If you select this option then your entire project with these files is published to remote location.  You can usually use this option to move your working project to any remote location and get working on it without having to do a physical copy of select files.  If you want to share your project with your friends over FTP this is a good option to use. Do note Publish feature does not publishes OBJ folder as it is not a folder that a user should really be worried about, it is just for temporary compilation use.
  • All files in the source Project Folder - Many a times users chose to exclude files from their projects by choosing the "Exclude From Project" command


This command essentially removes the artifact from the Project File, although do note that these files are still present in your source project folder.

Apart from this many a times users want to add help files, read me files, references docs (e.g. requirements doc) and other misc items in their project folder while they do not really want to publish these artifacts most of the time.

By choosing "All files in the source Project Folder" you can take all these files (excluding OBJ) folder and transfer it to any remote location via HTTP, FTP or simple disk IO to a UNC location.

The above three options kind of provides all the dials for a user to choose the appropriate publish option applicable to them.

  • Include files from the App_Data folder - App Data folder might potentially contain huge files and sensitive data, hence it is given a special status and you can choose whether or not you would like to publish your App_Data folder or not.  It is selected by default as VS assumes that you need the Data to run your application but if you really do not have anything in the App_Data folder or if you are hoping to use SQL Server in production (as opposed to MDF files & SQL Express during development) then you should go and uncheck this box.

Hope this summary of "Publish" feature for Web Application Projects helps...

No comments: