public override bool Execute() { // set to false first. IsEnvironmentValid = false; Target = Target.ToLower(); if (_environments.ContainsKey(Target)) { var env = _environments[Target]; if (env == null) { IsEnvironmentValid = false; return(true); } IsEnvironmentValid = true; EnvironmentUtility.Apply(env); return(true); } try { ArrayList targetLists = _msbuild.CreateTargetLists(new[] { Target }, false); var result = _msbuild.ExecuteTargets(new ITaskItem[] { null }, null, null, targetLists, false, false, BuildEngine3, Log, targetOutputs, false, false, null); if (result) { _environments.Add(Target, Environment.GetEnvironmentVariables()); IsEnvironmentValid = true; return(true); } } catch { // any failure here really means that it should just assume it didn't work. } _environments.Add(Target, null); IsEnvironmentValid = false; return(true); }