public static void Verify(ProjectOtherwiseElement viewXml, ProjectOtherwiseElement realXml, ValidationContext context = null) { if (viewXml == null && realXml == null) { return; } VerifyProjectElement(viewXml, realXml, context); Verify(viewXml.ChooseElements, realXml.ChooseElements, context); Verify(viewXml.ItemGroups, realXml.ItemGroups, context); Verify(viewXml.PropertyGroups, realXml.PropertyGroups, context); }
/// <summary> /// Adds an <Otherwise /> element to the current project. /// </summary> /// <param name="label">An optional label to add to the Otherwise.</param> /// <returns>The current <see cref="ProjectCreator"/>.</returns> /// <exception cref="ProjectCreatorException">A <When /> element has not been added /// -or- /// An <Otherwise /> has already been added to the current <Choose /> element.</exception> public ProjectCreator Otherwise(string label = null) { if (_lastWhen == null) { throw new ProjectCreatorException(Strings.ErrorOtherwiseRequiresWhen); } if (_lastChoose.OtherwiseElement != null) { throw new ProjectCreatorException(Strings.ErrorOtherwiseCanOnlyBeSetOnce); } ProjectOtherwiseElement projectOtherwiseElement = RootElement.CreateOtherwiseElement(); projectOtherwiseElement.Label = label; LastChoose.AppendChild(projectOtherwiseElement); return(this); }
protected virtual bool ParseChoose() { ICollection <ProjectChooseElement> chooseElements = _project.ChooseElements; if (chooseElements == null || chooseElements.Count == 0) { return(false); } List <ProjectPropertyGroupElement> conditionedGroups = new List <ProjectPropertyGroupElement>(); List <ProjectPropertyGroupElement> otherwiseGroups = new List <ProjectPropertyGroupElement>(); foreach (ProjectChooseElement chooseElement in chooseElements) { // Get the matching property groups in the When elements... foreach (ProjectWhenElement whenElement in chooseElement.WhenElements) { if (IsConditionMatched(this.Configuration, this.Platform, whenElement.Condition)) { ICollection <ProjectPropertyGroupElement> propertyGroups = whenElement.PropertyGroups; if (propertyGroups != null && propertyGroups.Count != 0) { conditionedGroups.AddRange(propertyGroups); } } } // Get the property groups in the Otherwise element, if available... ProjectOtherwiseElement otherwiseElement = chooseElement.OtherwiseElement; if (otherwiseElement != null) { ICollection <ProjectPropertyGroupElement> propertyGroups = otherwiseElement.PropertyGroups; if (propertyGroups != null && propertyGroups.Count != 0) { otherwiseGroups.AddRange(propertyGroups); } } } bool isSuccessful = false; // We parse the actual properties in the "second pass" since the MSBuild // project is unstructured format... if (conditionedGroups != null && conditionedGroups.Count != 0) { foreach (ProjectPropertyGroupElement propertyGroup in conditionedGroups) { if (this.ParseProperyGroup(propertyGroup)) { // There is no need to parse multiple project groups with the // same condition... isSuccessful = true; break; } } } // If not successful, try searching the Otherwise property groups... if (!isSuccessful && (otherwiseGroups != null && otherwiseGroups.Count != 0)) { foreach (ProjectPropertyGroupElement propertyGroup in otherwiseGroups) { if (this.ParseProperyGroup(propertyGroup)) { // There is no need to parse multiple project groups with the // same condition... isSuccessful = true; break; } } } return(isSuccessful); }