2. Property functions: if the piece of code is merely a couple of method calls, it can go anywhere
$() can go with the $([Class]::Method()) syntax. There are all kinds of limitations and the list of officially whitelisted methods is rather short — e.g. it does not include AssemblyName.GetAssemblyName — but whitelist checks can be disabled by setting the environment variable MSBUILDENABLEALLPROPERTYFUNCTIONS to 1.