Wednesday, November 11, 2020

MSBuild Copy Task AfterBuild VS2019

This time the issue is with MSBuild task that I set up in one of my project (in the project file). The task is to copy the dll to a different location after build is done. I copied the configuration over to a different project and guess what, it didn't work.

Problem

It worked flawlessly for a very long time with the following configuration:

<Target Name="AfterBuild">
  <Copy SourceFiles="..." DestinationFolder="..." />
</Target>

Solution

Two main differences between the two projects are the working on is a .NET Framework project and built in VS2017. The new one is a .NET Standard and built in VS2019. Apparently, there is a change for VS2019 that comes with updated MSBuild. It is no longer depends on the target name (it is a bad idea anyway) to determine when to execute the task. I update it to the following and then it works great.

<Target Name="AnyNameIsFine" AfterTargets="Build">
  <Copy SourceFiles="..." DestinationFolder="..." />
</Target>

For reference:

https://docs.microsoft.com/en-us/visualstudio/msbuild/copy-task?view=vs-2019

No comments:

Post a Comment