Typically, I have the answer to the question!
Instead of running a batch file to set the environment variables, use a custom MSBuild task to do it for you:
public class SetEnvVar : Task
{
private string _variable;
private string _value;
[Required()]
public string Variable
{
get { return _variable; }
set { _variable = value; }
}
[Required()]
public string Value
{
get { return _value; }
set { _value = value; }
}
public override bool Execute()
{
Environment.SetEnvironmentVariable(_variable, _value);
return true;
}
}
<Target Name="BeforeTest">
<SetEnvVar Variable="Cor_Enable_Profiling" Value="0x1" />
<SetEnvVar Variable="COR_PROFILER" Value="{B146457E-9AED-4624-B1E5-968D274416EC}" />
</Target>
<Target Name="AfterTest">
<SetEnvVar Variable="Cor_Enable_Profiling" Value="0x0" />
</Target>