After AfterTargets crashes, the msbuild run does not start

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?
+6
source share
1 answer

Have you tried adding <Error /> after the <Copy /> task to give an error if the contents of the source and destination are not the same?

0
source

Source: https://habr.com/ru/post/921830/


All Articles