views:

59

answers:

1

As part of one of my projects, there are "BeforeBuild" tasks that ultimately generate some files. In particular, it compiles a small static class (included as "do not compile" in the project) into it's own executable and then executes it, passing in an external input file outputting a new generated class to be included in the project.

I programmed it to put the intermediate files in the projects $(OutDir), but found that on "Rebuild" (and ultimately "Clean"), these files aren't picked up. After some thought, I realized that the final, generated class which is placed right in $(ProjectDir) should probably be deleted on "Clean" too.

Some investigation into Microsoft.Common.targets revealed that there was some "master list" from the intermediate path (obj\build\assembly.FileListAbsolute.txt) that was queried for the files to delete.

Is there some standard method of adding my new files to this list in MSBuild to have them cleaned up, or would this sort of thing fit better in a "BeforeClean" (or "AfterClean") target override?

A: 

See Extending the Clean Process for details of the FileWrites mechanism (which is the system writing the FileListAbsolute.txt you're seeing) in this MSBuild article by Hashimi. And get the book right now if you're going to spend more than 2 hours writing build scripts in the next year.

Ruben Bartelink
Perfect! *Extending the Clean Process* was exactly what I was looking for! I really hope to not have to spend more than 2 hours on build scripts over the next year, but that book will likely find its way to my desk in the near future.
Jeff Wight
@Jeff Wight: You can't hide from it -- it's well worth understanding MSBuild-ese, and you'll even come to appreciate it as elegant in time! http://stackoverflow.com/questions/47884/is-it-worth-learning-to-use-msbuild and http://stackoverflow.com/questions/1326445/is-there-a-good-tutorial-on-msbuild-scripts
Ruben Bartelink
Yeah I agree with Ruben get the book!
Sayed Ibrahim Hashimi