Wednesday, October 24, 2012

MSBuild incorrectly skips projects set to build for given configuration

I ran into this problem and couldn't find any solutions for it anywhere. I was using MSBuild with VS2012. When I tried to build my solution, there seemed not to be any rhyme or reason as to what projects it chose to build. I would get this message in the log:

The project "[MyProject]" is not selected for building in solution configuration "Debug|Any CPU".

If I opened the solution, opened the Build Configuration Manager, ensured "Debug" was selected under "Active solution configuration", looked at my project, ensured "Any CPU" was selected under platform, I could see that the box in the "Build" column was checked. Most (but not all) that were unchecked were built.

The solution for me was to just create a new solution configuration (an option in the "Active solution configuration" drop list). I named it "ForMSBuild" so as not to confuse other devs, and selected to copy the settings from Debug. I selected "Any CPU" in the "Active solution platform" drop list, ensured each project had "Any CPU" selected and made my "Build" selections as necessary. After adjusting the params passed to MSBuild to refer to this new configuration, it built correctly.

Update:  I later found that builds were run directly in visual studio using the main Debug configuration.  I was getting build errors in deprecated test projects that were set to not build in the configuration.  I'm convinced there is a bug in 2012.