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

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

Rate This
  • Comments 3

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.

ItemsToDeploy 

  • 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' ">
      ...
      <OutputPath>bin\</OutputPath>
     
      <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
      <
    ExcludeFilesFromDeployment>File1.aspx;File2.aspx</ExcludeFilesFromDeployment>
      <
    ExcludeFoldersFromDeployment>Folder1;Folder2</ExcludeFoldersFromDeployment>
    </
    PropertyGroup>

    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

Leave a Comment
  • Please add 4 and 6 and type the answer here:
  • Post
  • Is it possible to use MSBuild wildcards? For example:

    <ExcludeFilesFromDeployment>**\.svn\**\*.*</ExcludeFilesFromDeployment>

  • I guess I could have tried it before asking. They do work.

  • Hi, i have a deployment question.  In a solution with 4 projects, how do I create a package that puts the contents of 3 projects under 1 project but inside a folder.  For example:

    Project 1Contents

       L  Modules Folder

                                 L Project 2 Contents

                                 L Project 3 Contents

                                 L Project 4 Contents

    Everytime i fire a build, all project contents appear at the same level

    Hope you can help.  

    Thanks!

Page 1 of 1 (3 items)