Search code examples
visual-studiovisual-studio-2005web-publishing

Exclude files from web site publish in Visual Studio


Can I exclude a folder or files when I publish a web site in Visual Studio 2005? I have various resources that I want to keep at hand in the Solution Explorer, such as alternate config files for various environments, but I don't really want to publish them to the server. Is there some way to exclude them? When using other project types, such as a .dll assembly, I can set a file's Build Action property to "None" and its Copy to Output Directory property to "Do not copy". I cannot find any similar settings for files in a web site.

If the IDE does not offer this feature, does anyone have good technique for handling such files?


Solution

  • If you can identify the files based on extension, you can configure this using the buildproviders tag in the web.config. Add the extension and map it to the ForceCopyBuildProvider. For example, to configure .xml files to be copied with a publish action, you would do the following:

    <configuration>...
        <system.web>...
            <compilation>...
                <buildProviders>
                    <remove extension=".xml" />
                    <add extension=".xml" type="System.Web.Compilation.ForceCopyBuildProvider" />
                </buildProviders>
    

    To keep a given file from being copied, you'd do the same thing but use System.Web.Compilation.IgnoreFileBuildProvider as the type.