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,

  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”>

    • Jenelle says:

      What a pleusare to find someone who thinks through the issues

    • 22/04/2010 – 2:52pmLa portada es de mal gusto. Es totalmente una hipocresía que hayan querido dedicar la portada a Samaranch y lo mezclen con noticias del corazon made in marca con parrafito del subnormal incluido. No entiendo porque hay comentarios que dicen que es una portada coherente. Bueno si lo entiendo, cada uno tiene su opinión.

    • Grim 5“But when you take the hardass, just make sure you know what’s really a costly problem, and what’s expected given the age and condition of the property.” If you can not figure out what is something big and what is to be expected maybe you should not be signing loan docs anyway. I guess it is just age talking as I would know, but looking back to my first purchase over 20 years ago I surely would have asked people in the area of problem to get a feel (no internet then, now easier).

    • CieszÄ™ siÄ™, że miÅ‚ość kwitnie, że Ty kwitniesz, że drzewa w Polsce kwitnÄ… (tak tak, drzewa majÄ… paki, bo nie ma Å›niegu). Podziwiam, że sobie radzisz czasowo ze wszytskim, ja ledwo co ogarniam. Tak czy siak, fajnie, że siÄ™ Tobie ukÅ‚ada i bardzo przyjemnie siÄ™ czyta takie notki.

  6. If you ask individuals to describe Madrid using some words,
    odds are « Nature » won’t surface often. Top Spain City Breaks Barcelona, Madrid, Valencia, Palma de Mallorca, Ibiza Town, Seville, Granada, C.
    The Arye Hotel Gran Via happens to be a popular choice for plenty of tourists trying
    to find Madrid hotels.

Leave a Reply