Saturday, September 9, 2006

How to force Visual Studio to recompile project at "Build" action

Our solution contains about 30 projects. There are web apps, windows services, web controls, web parts (usual stuff for SharePointers). One of them is a BuildApp. It contains only one empty file class1.cs but it's there to register DLLs in GAC, web parts in SPS and restart appPool.

After installing Visual Studio 2003 SP1 the BuildApp is not compiled during build operation. VS detects that it's up to date and leaves it. It's cool, it should be like that (why it compiled it before?)

But if BuildApp is not compiled, post build events are not fired. This forces us to run them manually. Personally I am a lazy but productive developer so I decided to fix it.

To fool VS to think that the project needs to be compiled, open one of the compiled files (the empty file which nobody will edit again), change date to something in far future like 2010, edit file and save it.
If you use SourceSafe edit the file outside the VS and remove "read only" attribute manually (apply is after edit has been made).

Thanks to this trick VS will compile the project every time you do the "build" and run post build events - sweet!

It works for Visual Studio 2003 SP1 and Visual Studio 2005

2 comments:

Anonymous said...

Well thanks for that entry. The trick with the future date works fine in my c++ project, and the build event always runs.

thanks,
Norbert

Sebastian said...

glad I could help!