I'm struggling with the following problem and I don't get it. I have a Visual Studio Xamarin project (VS 2019 on Windows 10). In the project file I defined a custom build target:
<Target Name="MyCustomTarget" AfterTargets="PrepareForBuild">
<Message Importance="high" Text="=== executing MyCustomTarget" />
<!-- do some file modifications -->
</Target>
I want it to run always after the predefined PrepareForBuild target. When I build the project, my target is executed and I see it in the build output (my custom message is shown also some files are updated as defined in the target).
The problem is that my custom target also executes (maybe even several times!), when I execute the "clean" command for the project. In this case I don't see my message in the output log (MSBuild verbosity is set to diagnostic in the options), the target is also not listed in the task performance summary, but it is executed (my files are updated). This is something I don't understand. The PrepareForBuild target is also not executed, when clean is called. Why does my target execute even when clean is called?
If I change my task to execute after BeforeBuild, then it is not called, when clean is executed, but I need it to execute earlier then after BeforeBuild.