Tuesday, January 22, 2008

Visual Studio 2005 Customizing build process

Visual Studio 2005 provides a great set of features to customize the build process. Recently, I had an requirement to customize the build process for an in house web application to conditionally include files and project references. In my case, I had an web application projects and multiple library projects which were being references by the webapp. For one particular installation, I had to exclude one library project (say Project One ) and several aspx pages in the web app that were using Project One. MSDN had a nice article on a new feature called web deployment project which allows to customize the build process. But, I didn't want to add an additional project to existing solution, so I tried to solve my problem in a different way.

1. I created a seperate build configuration named "ExcludeProjectOne". Right click on Solution->Choose Configuration Manager->Select New from Active Configuration.
2. Uncheck the project you don't want to build in that configuration (Here, it is ProjectOne)

Now, when you choose the active configuration as ExcludeProjectOne, the library project "Project One" is excluded from the build process. But, it still didn't solve the problem in my web app project which references the ProjectOne and some aspx files which uses it. So, I manually edited the Web.csproj file to achieve the desired action.

I created a new itemgroup element with a condition attribute and placed all the necessary files and the project reference inside the itemgroup element.

The above changes allowed to me have a build configuration for the web application where I can exclude the library and the related aspx pages being built.

No comments: