Excluding files from Visual Studio web deployment

The other day at work, I was fine tuning the deployment process for one of our internal web sites.  One of the issues we had were a set of assemblies that were referenced by the web project but which needed to be excluded from deployment.

The process of excluding files is very simple, but requires some knowledge of how publishing in VS works.  I’m using VS2012 with Update 2 installed, though this feature might have been added before that.

Step 1: During File Preview, determine the list of files you want to exclude

For this exercise, I’ll exclude the following files:


Step 2: Modify the .pubxml

The edit to you publish profiles is very easy: just set the ExcludeFilesFromDeployment property.  In my publish profile (the .pubxml file), I added the following lines within the PropertyGroup:


Note that you can also use wildcards here if your file names are patterned.

There was also previously a property called ExcludeFilesFromPackage, but I prefer ExcludeFilesFromDeployment as it clarifies that this is not limited to just using WebDeploy packages.

Step 3: Verify that the files are excluded

Now when I do the file Preview again, I see that those files are no longer shown in the list (note: I haven’t actually published any files yet)


When I publish, the files are also not included:


It’s that easy!


  1. Daz Johnson says:

    If the file you are excluding is referenced by another file then this does not work.

    If my web.config contains a reference to a separate file such as

    and I exclude the connectionstrings file, the deploy fails because it “can not find” the referenced file.

    Very frustrating.

  2. Daz Johnson says:

    looks like my xml snippet was censored.

    Trying square brackets instead of angled :)

    [connectionStrings configSource=”configconnectionstrings.config” /]

    • Jimmy says:

      Hi Daz,

      Does the deployment fail, or does the app fail to run afterwards? The deployment doesn’t pre-validate the successful execution of the app, so it sounds like in this case you’re setting up an invalid set of files on the remote server, unless I’m misunderstanding the scenario.

  3. Note that, although not explicitly stated above, you can exclude a file within a folder by using FolderName\FileName. Thus, if you wanted to exclude bin\WebApplication2.dll along with the other files indicated above, you would use “ExcludeThisFile.aspx;DoNotDeploy.aspx;bin\WebApplication2.dll”.

  4. Jeanie says:

    Hi Jimmy,
    nice article and clear solution :)
    I added an additional tag to skip folders and it works:


    Now I’m wondering if this approach could be used to accomplish an odd requirement:
    building an incremental package, that contains only those files that are subject to change (I would like to avoid redistribuiting external libraries files, since we cannot update libraries within minor releases of the application).

    Something similar is discussed in this thread: http://forums.asp.net/t/1667062.aspx?incremental+deployment+package+

    Thank you,

    • Jeanie says:

      XML snippet on my previous post looks broken, let’s try using square brakets instead of angled:


  5. Jeanie says:

    I solved by extending your suggestion in this way:


    <!– exclude from being added to deploy package –>

    <!– prevent deletion from destination folder –>
    <Target Name=”addCustomSkipRules”>
    <MsDeploySkipRules Include=”skipScripts”>
    <MsDeploySkipRules Include=”skipDropzoneScripts”>

Leave a Reply to Jeanie