public async Task <XDocument> WriteSpriteRecipe() { string root = ProjectHelpers.GetRootFolder(); XmlWriterSettings settings = new XmlWriterSettings() { Indent = true }; XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; if (string.IsNullOrEmpty(root)) { root = ProjectHelpers.GetProjectFolder(FileName); } ProjectHelpers.CheckOutFileFromSourceControl(FileName); using (XmlWriter writer = await Task.Run(() => XmlWriter.Create(FileName, settings))) { XDocument doc = new XDocument( new XElement("sprite", new XAttribute(XNamespace.Xmlns + "xsi", xsi), new XAttribute(xsi + "noNamespaceSchemaLocation", "http://vswebessentials.com/schemas/v1/sprite.xsd"), new XElement("settings", new XComment("Determines if the sprite image should be automatically optimized after creation/update."), new XElement("optimize", Optimize.ToString().ToLowerInvariant()), new XComment("Determines the orientation of images to form this sprite. The value must be vertical or horizontal."), new XElement("orientation", IsVertical ? "vertical" : "horizontal"), new XComment("The margin (in pixel) around and between the constituent images."), new XElement("margin", Margin), new XComment("File extension of sprite image."), new XElement("outputType", FileExtension.ToString().ToLowerInvariant()), new XComment("Determine whether to generate/re-generate this sprite on building the solution."), new XElement("runOnBuild", RunOnBuild.ToString().ToLowerInvariant()), new XComment("Use full path to generate unique class or mixin name in CSS, LESS and SASS files. Consider disabling this if you want class names to be filename only."), new XElement("fullPathForIdentifierName", UseFullPathForIdentifierName.ToString().ToLowerInvariant()), new XComment("Use absolute path in the generated CSS-like files. By default, the URLs are relative to sprite image file (and the location of CSS, LESS and SCSS)."), new XElement("useAbsoluteUrl", UseAbsoluteUrl.ToString().ToLowerInvariant()), new XComment("Specifies a custom subfolder to save files to. By default, compiled output will be placed in the same folder and nested under the original file."), new XElement("outputDirectory", OutputDirectory), new XComment("Specifies a custom subfolder to save CSS files to. By default, compiled output will be placed in the same folder and nested under the original file."), new XElement("outputDirectoryForCss", CssOutputDirectory), new XComment("Specifies a custom subfolder to save LESS files to. By default, compiled output will be placed in the same folder and nested under the original file."), new XElement("outputDirectoryForLess", LessOutputDirectory), new XComment("Specifies a custom subfolder to save SCSS files to. By default, compiled output will be placed in the same folder and nested under the original file."), new XElement("outputDirectoryForScss", ScssOutputDirectory) ), new XComment("The order of the <file> elements determines the order of the images in the sprite."), new XElement("files", BundleAssets.Select(file => new XElement("file", "/" + FileHelpers.RelativePath(root, file)))) ) ); doc.Save(writer); return(doc); } }
public async Task <XDocument> WriteBundleRecipe() { string root = ProjectHelpers.GetRootFolder(); if (string.IsNullOrEmpty(root)) { root = ProjectHelpers.GetProjectFolder(FileName); } XmlWriterSettings settings = new XmlWriterSettings() { Indent = true }; XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; ProjectHelpers.CheckOutFileFromSourceControl(FileName); using (XmlWriter writer = await Task.Run(() => XmlWriter.Create(FileName, settings))) { XDocument doc = new XDocument( new XElement("bundle", new XAttribute(XNamespace.Xmlns + "xsi", xsi), new XAttribute(xsi + "noNamespaceSchemaLocation", "http://vswebessentials.com/schemas/v1/bundle.xsd"), new XElement("settings", new XComment("Determines if the bundle file should be automatically optimized after creation/update."), new XElement("minify", Minified.ToString().ToLowerInvariant()), new XComment("Determine whether to generate/re-generate this bundle on building the solution."), new XElement("runOnBuild", RunOnBuild.ToString().ToLowerInvariant()), new XComment("Specifies a custom subfolder to save files to. By default, compiled output will be placed in the same folder and nested under the original file."), new XElement("outputDirectory", OutputDirectory) ), new XComment("The order of the <file> elements determines the order of the files in the bundle."), new XElement("files", BundleAssets.Select(file => new XElement("file", GetRelativePath(file, root)))) ) ); if (isCss) { doc.Descendants("runOnBuild").FirstOrDefault().AddAfterSelf( new XComment("Use absolute path in the generated CSS files. By default, the URLs are relative to generated bundled CSS file."), new XElement("adjustRelativePaths", AdjustRelativePaths.ToString().ToLowerInvariant()) ); } doc.Save(writer); return(doc); } }