One thing Powershell has that MSBuild hasn't is a scripting engine that can access the .NET core libraries directly. For example, in Powershell you could use the following function to get the current day of the week and assign it to a variable:
$a = (get-date).dayofweek
In the MSBuild world we are restricted to writing a custom task to access the .NET core libraries, but I thought I'd have a go at writing a stepping stone when you just want to access .NET from within MSBuild without having to compile anything. The result is essentially a fusion of a basic MSBuild custom task and CodeDom technology and the source code is attached.
Here is a simple example of its usage:
This script simply returns the Day of the Week and assigns it to the $(DynamicCodeResult) property so it could be later used in the script.
I realised I needed to add a way of injecting references into the code so it would compile (for example if I wanted to use the System.Xml namespace). So I added this support, resulting in the following slightly more sophisticated example:
Simply, this piece of code loops through an RSS feed and pulls out the title of each post. Note the additional "Using" and "ReferencedAssemblies" attributes on the DynamicCode task. I'm sure you get the idea.
I've only supported C# and a return type of string for now from the dynamically executed code but the source is attached so feel free to make some customisations and leave a comment on how you are using it.