23
votes

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?

1

1 Answers

22
votes

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.