In my solution, some projects have tasks that need to be completed at the end, for example, copy files to different places. We implement this with AfterTargets="Build" :
<Target Name="CopyStuff" AfterTargets="Build"> <Copy SourceFiles="..." DestinationFolder="..." /> </Target>
If it works. However, when creating a solution (and not in a separate project!), If the copy fails, we get a warning about red build, but msbuild (and, therefore, the TFS build) succeeds:
> msbuild /t:clean;build my.sln (...) (in red...) error MSB3021: Unable to copy file (...) > echo %errorlevel% 0 <<<<<<< This means succeeded
As far as I understand, this is because msbuild believes that as long as the main purpose of "Build" has passed, everything has passed too.
Our workaround. Change the target to BeforeTargets="AfterBuild" , which puts my target in the build target. However, this requires knowledge of the contents of the Create goal and may not work for other types of projects.
Question:
- Is there a way to get
AfterTargets="Build" errors for solution build failures? - If not, is there a way to automatically verify that people have not added
AfterTargets="Build" to their projects?
source share