private void LoadProperties(IEnumerable<XElement> propertyGroups, PropertyValues props) { foreach (var propertyGroup in propertyGroups) { if (Condition(propertyGroup, props)) { foreach (var propElement in propertyGroup.Elements()) { if (Condition(propElement, props)) { props[propElement.Name.LocalName] = propElement.Value; } } } } }
private bool Condition(XElement element, PropertyValues props) { XAttribute condition = element.Attribute("Condition"); if (condition != null) { try { var parser = new ProjectFilePropertyExpressionParser(props); return parser.ParseCondition(condition.Value); } catch (ConditionParseException) { return false; } } else { return true; } }
public VisualStudioProject LoadProject(string path, string projectName, string configuration) { XDocument proj = XDocument.Load(path); var props = new PropertyValues(); props["Configuration"] = configuration; var propertyGroups = proj.Element(msbuild + "Project").Elements(msbuild + "PropertyGroup"); LoadProperties(propertyGroups, props); var projectDirectory = Path.GetDirectoryName(path); var outputDirectory = Path.Combine(projectDirectory, props["OutputPath"]); var outputFile = Path.Combine(outputDirectory, props["AssemblyName"] + "." + GetExtensionForOutputType(props["OutputType"])); return new VisualStudioProject { OutputFile = outputFile.TrimEnd('\\'), OutputDirectory = outputDirectory.TrimEnd('\\'), Name = projectName, ProjectFile = path, ProjectDirectory = projectDirectory, }; }
public void SetUp() { Props = new PropertyValues(); Parser = new ProjectFilePropertyExpressionParser(Props); }