Archive for April 2013

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:

FilesToExcludeFromPublish

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:

    <ExcludeFilesFromDeployment>
      ExcludeThisFile.aspx;DoNotDeploy.aspx
    </ExcludeFilesFromDeployment>

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)

image

When I publish, the files are also not included:

image

It’s that easy!