public FileDescriptionTemplate(XmlElement xml, string hintPath) { TemplateLoadException.AssertAttributeExists(xml, "name"); name = xml.GetAttribute("name"); language = xml.GetAttribute("language"); if (xml.HasAttribute("buildAction")) { itemType = xml.GetAttribute("buildAction"); } foreach (XmlAttribute attribute in xml.Attributes) { string attributeName = attribute.Name; if (!knownAttributes.Contains(attributeName)) { if (attributeName == "copyToOutputDirectory") { ProjectTemplate.WarnObsoleteAttribute(xml, attributeName, "Use upper-case attribute names for MSBuild metadata values!"); attributeName = "CopyToOutputDirectory"; } if (attributeName == "dependentUpon") { ProjectTemplate.WarnObsoleteAttribute(xml, attributeName, "Use upper-case attribute names for MSBuild metadata values!"); attributeName = "DependentUpon"; } if (attributeName == "subType") { ProjectTemplate.WarnObsoleteAttribute(xml, attributeName, "Use upper-case attribute names for MSBuild metadata values!"); attributeName = "SubType"; } metadata[attributeName] = attribute.Value; } } if (xml.HasAttribute("src")) { string fileName = Path.Combine(hintPath, StringParser.Parse(xml.GetAttribute("src"))); try { if (xml.HasAttribute("binary") && bool.Parse(xml.GetAttribute("binary"))) { contentData = File.ReadAllBytes(fileName); } else { content = File.ReadAllText(fileName); } } catch (Exception e) { content = "Error reading content from " + fileName + ":\n" + e.ToString(); LoggingService.Warn(content); } } else { content = xml.InnerText; } }
void LoadElement(XmlElement node, string hintPath) { switch (node.Name) { case "Options": ProjectTemplate.WarnObsoleteNode(node, "Options are no longer supported, use properties instead."); break; case "CreateActions": LoadCreateActions(node); break; case "PreCreateActions": LoadPreCreateActions(node); break; case "ProjectItems": LoadProjectItems(node); break; case "Files": LoadFiles(node, hintPath); break; case "Imports": LoadImports(node); break; case "PropertyGroup": LoadPropertyGroup(node); break; case "Include": TemplateLoadException.AssertAttributeExists(node, "src"); string includeFileName = Path.Combine(hintPath, node.GetAttribute("src")); try { XmlDocument doc = new XmlDocument(); doc.Load(includeFileName); doc.DocumentElement.SetAttribute("fileName", includeFileName); if (doc.DocumentElement.Name == "Include") { LoadElementChildren(doc.DocumentElement, Path.GetDirectoryName(includeFileName)); } else { LoadElement(doc.DocumentElement, Path.GetDirectoryName(includeFileName)); } } catch (XmlException ex) { throw new TemplateLoadException("Error loading include file " + includeFileName, ex); } break; default: throw new TemplateLoadException("Unknown node in <Project>: " + node.Name); } }
void LoadImports(XmlElement importsElement) { if (string.Equals(importsElement.GetAttribute("clear"), "true", StringComparison.OrdinalIgnoreCase)) { clearExistingImports = true; } foreach (XmlElement importElement in ChildElements(importsElement)) { TemplateLoadException.AssertAttributeExists(importElement, "Project"); projectImports.Add(new Import( importElement.GetAttribute("Project"), importElement.HasAttribute("Condition") ? importElement.GetAttribute("Condition") : null )); } }