I'm trying to convert this C# code to run in MSBuild:
var uri = new Uri(s1);
var result = uri.MakeRelativeUri(new Uri(s2)).ToString();
<Exec Command="powershell '(New-Object [System.Uri] ...'" />
I am not sure what your goal is, but if you really need MSBuild to run some C# code, you need to use inline tasks. See MSDN's Walkthrough: Creating an Inline Task
Most of the time MSBuild runs pre-compiled tasks and command line utilities.