コード例 #1
0
		/// <summary>
		/// Evaluates the specified condition in the project.
		/// WARNING: EvaluateCondition might add a temporary property group and remove it again,
		/// which invalidates enumerators over the list of property groups!
		/// </summary>
		internal static bool EvaluateCondition(MSBuild.Project project,
		                                       string condition)
		{
			const string propertyName = "MSBuildInternalsEvaluateConditionDummyPropertyName";
			MSBuild.BuildPropertyGroup pGroup = project.AddNewPropertyGroup(true);
			pGroup.AddNewProperty(propertyName, "ConditionFalse");
			pGroup.AddNewProperty(propertyName, "ConditionTrue").Condition = condition;
			bool result = project.GetEvaluatedProperty(propertyName) == "ConditionTrue";
			project.RemovePropertyGroup(pGroup);
			return result;
		}