As an update to http://blog.seravy.com/solution-wide-msbuild-target/ I am happy to report that there is a far easier way to add in custom logic to all common project types in visual studio 2017/MSBuild 15.
As a result of the issue https://github.com/Microsoft/msbuild/issues/222 there in common.targets (and so most project types) will attempt to import the file Directory.Build.targets and/or Directory.Build.props in the same folder and traverse up until it hits the root drive. This means provided your solution is in a parent directory of all your project files it will load a Directory.Build.targets or/and Directory.Build.props in the same directory as it.
If you had multiple solutions and wanted to include specific logic for each of them you could use the $(SolutionPath) variable to put conditional logic.
See the example on github and run the solution from visual studio 2017 or run the batch file.
1>------ Rebuild All started: Project: ClassLibrary, Configuration: Debug Any CPU ------
2>------ Rebuild All started: Project: ConsoleApp, Configuration: Debug Any CPU ------
2> ConsoleApp -> C:\Users\Seravy\Desktop\Directory.Build.Example\ConsoleApp\bin\Debug\ConsoleApp.exe
2> Scope: Project. I performing an action per project from a solution include. C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0 C:\Users\Seravy\AppData\Local\Microsoft\MSBuild\15.0
1> ClassLibrary -> C:\Users\Seravy\Desktop\Directory.Build.Example\ClassLibrary\bin\Debug\ClassLibrary.dll
1> Scope: Project. I performing an action per project from a solution include. C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0 C:\Users\Seravy\AppData\Local\Microsoft\MSBuild\15.0
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========