Move definitions of BeforeBuild and AfterBuild targets to .props instead of .targets files
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
The `BeforeBuild` and `AfterBuild` targets are currently defined in [Microsoft.Common.CurrentVersion.targets](https://github.com/Microsoft/msbuild/blob/ca7b47d21088068aa7f8055b5637c5eb5ab500db/src/XMakeTasks/Microsoft.Common.CurrentVersion.targets#L783-L792). I presume that the intention was for you to override them in your project files after the .targets import near the bottom of the file.
However, if you're using the new `Sdk` attribute on the `Project` element, it's not possible to put a target definition after the default .targets import. This can lead to targets that people put in their project files unexpectedly not running, with no indication why unless you examine the log file and see the message that the target has been overridden (for example, https://github.com/dotnet/sdk/issues/841).
It would be better to define the empty `BeforeBuild` and `AfterBuild` targets in a .props file so that if they occur in the body of a project the ones from the project take precedence.
@AndyGerlicher @rainersigwald @cdmihai What do you think about the compat implications of this and when we could make such a change? If we changed it for all situations, then targets defined in the "wrong" place in project files would start running where they hadn't previously. If we are not OK with that, we could change to conditionally defining these targets where they currently are, and then define them in a .props file of the .NET SDK along with a property telling the default MSBuild targets not to define them.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.