views:

2691

answers:

3

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?

A: 

The feature you are looking exists if your project is created as a "Web Application". Web Site "projects" are just a collection of files that are thought of as 1:1 with what gets deployed to a web server.

In terms of functionality both are the same, however a web application compiles all source code to a DLL, instead of the naked source code files being copied to the web server and compiled as needed.

David
+1  A: 

I think you only have two options here:

  • Use the 'Exclude From Project' feature. This isn't ideal because the project item will be excluded from any integrated IDE source control operations. You would need to click the 'Show All Files' button on the Solution window if you need to see the files in Solution Explorer, but that also shows files and folders you're not interested in.
  • Use a post-build event script to remove any project items you don't want to be published (assuming you're publishing to a local folder then uploading to the server).

I've been through this before and couldn't come up with anything really elegant.

HTH
Kev

Kev
+4  A: 

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.

Chris Hynes