Thursday, 20 November 2008

Scary MSBuild log

This is not what you want to see in your MSBuild log:


This unwelcome tale appeared in my log because I had this Target in the project file:

<Target Name="DeleteOldResultFiles">
         <LogFile Include="$(ReportsDirectory)\*.*"/>
   <Delete Files="@(LogFile)" TreatErrorsAsWarnings="true"/>

Unfortunately, I had miss-typed the $(ReportsDirectory) property as $(ReportDirectory), and said miss-typed property did not exist, so MSBuild was defaulting to the empty string. Thus the LogFile Item was being populated with a list of all the files in my C:\ drive, and the Delete task was obediently purging them.

The moral of this story: don't run MSBuild as Admin - or if you're as foolish as I was, make sure you've at least got a cloned Virtual machine (as I had) from which to copy any files which might get trashed.


Post a Comment