Web Deployment: Excluding Files and Folders via the Web Application’s Project File

Web Development Tools Microsoft

Web Deployment (see this posting for an overview) offers a set of pre-determined options to allow users to include the most common sets of files for deployment.  These options are as follows and can be found under the “Items to deploy” section on the Package / Publish Web property page.


  • Only files needed to run this application:  This will include only the files required to run the application.  Specifically, files to be included will be those found in the bin folder and those files whose Build Action property = Content (such as .aspx, .ascx, and .master).
  • All files in this project:  This will include all files within the project file.
  • All files in this project folder:  This will include all files in the source project folder, including those not listed in the project file and those marked as ‘exclude’.

Excluding Specific Files / Folders
If these pre-determined options do not provide the exclusions required and you desire the flexibility to exclude specific files and/or folders while at the same time leaving them in your actual project, you can directly edit the web application’s project file to accomplish your goal.

Here are the steps to follow in order to exclude specific file(s) and/or folder(s) from packaging and/or publishing:

  1. Open the web application project file (.csproj or .vbproj) in an editor or from within Visual Studio itself (see this post).
  2. Add an <ExcludeFilesFromDeployment> and/or <ExcludeFoldersFromDeployment> element in the desired <PropertyGroup> element.

    Project File excerpt containing an example excluding the specific files, File1.aspx and File2.aspx, as well as the specific folders, Folder1 and Folder2, from deploying with the Debug configuration:

    <PropertyGroup Condition=‘$(Configuration)|$(Platform)’ == ‘Debug|AnyCPU’ >

    Note:  As packaging and publishing are configuration aware, these elements can be included in any custom configuration defined within the project file (not just the debug configuration), thereby making it possible to use the same base project while choosing to exclude different sets of files or folders from publishing (or packaging) under different custom configurations.

    File Variation:  Excluding a file under a folder (rather than at the root of the web application).  For example, if File2.aspx in the sample above was under a folder named FileSamples; the <ExcludeFilesFromDeployment> element would look like this:  <ExcludeFilesFromDeployment>File1.aspx;FileSamples\File2.aspx</ExcludeFilesFromDeployment>

    Folder Variation:  Excluding a folder under another folder (rather than at the root of the web application).  For example, if Folder1 in the sample above was under a folder named FolderCollection; the <ExcludeFoldersFromDeployment> element would look like this:  <ExcludeFoldersFromDeployment>FolderCollection\Folder1</ExcludeFoldersFromDeployment>

  3. Save the project file
  4. Reload the project
  5. Build your Deployment Package or Publish Web …

You will see that the files and/or folders you included within the <Exclude…> elements are not in your package (if that is what you chose to do) or at you publishing destination.

Hope this helps and happy web deploying,
Nichole Baker | Visual Web Developer


Discussion is closed.

Feedback usabilla icon