public static bool ShouldRunOn(this ProjectItem projectItem, RunOnBuild whenToRun, bool runIfDefault) { var setting = new AutoT4ProjectItemSettings(projectItem).RunOnBuild; return(setting == whenToRun || (setting == RunOnBuild.Default && runIfDefault)); }
private void RunTemplates(vsBuildScope scope, RunOnBuild buildEvent, bool runIfDefault) { _dte.GetProjectsWithinBuildScope(scope) .FindT4ProjectItems() .ThatShouldRunOn(buildEvent, runIfDefault) .ToList() .ForEach(item => item.RunTemplate()); }
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); } }
/// <summary> /// Converts the old <see cref="bool"/> <see cref="RunOnBuild"/> property to <see cref="RunOnBuild"/> /// </summary> private RunOnBuild CoerceOldRunOnBuildValue(string value) { var newRunOnBuildValue = DefaultRunOnBuildSetting; bool previousRunOnBuild; if (bool.TryParse(value, out previousRunOnBuild)) { newRunOnBuildValue = previousRunOnBuild ? RunOnBuild.Default : RunOnBuild.Disabled; } // Coercion was needed, therefore the new value needs to be assigned so that it gets migrated in the settings RunOnBuild = newRunOnBuildValue; return(newRunOnBuildValue); }
public static IEnumerable <ProjectItem> ThatShouldRunOn(this IEnumerable <ProjectItem> projectItems, RunOnBuild whenToRun, bool runIfDefault) { return(projectItems.Where(projectItem => projectItem.ShouldRunOn(whenToRun, runIfDefault))); }
public static IEnumerable<ProjectItem> ThatShouldRunOn(this IEnumerable<ProjectItem> projectItems, RunOnBuild whenToRun, bool runIfDefault) { return projectItems.Where(projectItem => projectItem.ShouldRunOn(whenToRun, runIfDefault)); }
public static bool ShouldRunOn(this ProjectItem projectItem, RunOnBuild whenToRun, bool runIfDefault) { var setting = new AutoT4ProjectItemSettings(projectItem).RunOnBuild; return setting == whenToRun || (setting == RunOnBuild.Default && runIfDefault); }