Automatic 'Include in Project' for folders in Visual Studio Projects

In my development team we have front-end developers (the FEDs) who almost always share TFS project structures with the back-end developers (BEDs - doesn’t sound as good.) The FEDs are usually using the shell integration for TFS and never really open the VS project files. As the front-end developers are not including their new files or folders this leaves an issue with deployments, quite often the files added by the FEDs will be left out of a deployment because they have not been ‘included’ in the project within VS. Here’s how we've been getting around it.

At the point of creating our VS web application projects it's common for us to know the folder structure to be used as we are normally working with the standard folder structure set out by of one of the CMSs we are extending. With this ‘templated’ folder structure we know what folders the FEDs will be accessing and whoever is doing deployments (whether it’s a developer or build server) will not accidentally leave out files. This can be embarrassing - and a complete waste of time - if the package is being sent somewhere and they discover nothing works or looks as it should, then having to re-deploy once again after including the missing files.

Since we know the folders, we can modify our project file to automatically include the files below the folders. This is done by adding references to the folders within an section in the source of the project file, it can be one that already exists that is declaring which files are content or to be compiled or you can just add your own.

If you wanted to automatically include all descendant files below a specific folder:

<Content Include="Path\To\Folder\**" />

This can be restricted to include only files within the path specified:

<Content Include="Path\To\Folder\*.*" />

Or even only files with a specified extension:

<Content Include="Path\To\Folder\*.jpg" >

In my case (a lot of the time) I know much of the folder structure when I start a project but even if you didn’t, as is a really quick job and only has to be done once for each time a folder is created – so you should only have to do this a few times during an entire project.

Heads up.

Make sure each entry is only in the project file once. If you have multiple entries for files or folders, the Solution Explorer will display them for each time it’s referenced. So if you have one reference of /images/logo.gif and another for /images/* then logo.gif will appear twice in the Solution Explorer.

If you do a ‘get latest version’ from your source control (TFS in my case) and there are new files, I don’t believe Solution Explorer will display the new files as included in the project. You must reload the project in order for them to be included. DO NOT ‘Include In Project’ for the individual files, this will cause the file to be duplicated in Solution Explorer next time you load the project/solution.

Lastly I must say that this is not in my plan to stop front-end and back-end developers communicating, it’s merely something to help developers keep their time on developing and not wasting it on redeploying projects when they shouldn’t need to.