private static void InstallPackage(IReadOnlyList <string> packages, bool quiet = false) { List <string> toInstall = new List <string>(); foreach (string package in packages) { if (package.Exists()) { TemplateCache.Scan(package); } else { toInstall.Add(package); } } NuGetUtil.InstallPackage(toInstall, quiet); TemplateCache.WriteTemplateCaches(); if (!quiet) { ListTemplates(new CommandArgument()); } }
static void UpdateCache() { if (dontUpdateCache) //Avoid updating cache while scan paths are added during registration { return; } var paths = new Paths(environmentSettings); //TODO: Uncomment this IF, but also add logic to invalidate/check if new templates were added from newly installed AddOns... //if (!paths.Exists (paths.User.BaseDir) || !paths.Exists (paths.User.FirstRunCookie)) { paths.DeleteDirectory(paths.User.BaseDir); //Delete cache var _templateCache = new TemplateCache(environmentSettings); foreach (var scanPath in TemplatesNodes.Select(t => t.ScanPath).Distinct()) { _templateCache.Scan(scanPath); } _templateCache.WriteTemplateCaches(); paths.WriteAllText(paths.User.FirstRunCookie, ""); //} var templateInfos = templateCreator.List(false, (t, s) => new MatchInfo()).ToDictionary(m => m.Info.Identity, m => m.Info); var newTemplates = new List <MicrosoftTemplateEngineSolutionTemplate> (); foreach (var template in TemplatesNodes) { ITemplateInfo templateInfo; if (!templateInfos.TryGetValue(template.Id, out templateInfo)) { LoggingService.LogWarning("Template {0} not found.", template.Id); continue; } newTemplates.Add(new MicrosoftTemplateEngineSolutionTemplate(template, templateInfo)); } templates = newTemplates; }
private void InstallLocalPackages(IReadOnlyList <string> packageNames) { List <string> toInstall = new List <string>(); foreach (string package in packageNames) { if (package == null) { continue; } string pkg = package.Trim(); pkg = _environmentSettings.Environment.ExpandEnvironmentVariables(pkg); string pattern = null; int wildcardIndex = pkg.IndexOfAny(new[] { '*', '?' }); if (wildcardIndex > -1) { int lastSlashBeforeWildcard = pkg.LastIndexOfAny(new[] { '\\', '/' }); pattern = pkg.Substring(lastSlashBeforeWildcard + 1); pkg = pkg.Substring(0, lastSlashBeforeWildcard); } try { if (pattern != null) { string fullDirectory = new DirectoryInfo(pkg).FullName; string fullPathGlob = Path.Combine(fullDirectory, pattern); _templateCache.Scan(fullPathGlob); } else if (_environmentSettings.Host.FileSystem.DirectoryExists(pkg) || _environmentSettings.Host.FileSystem.FileExists(pkg)) { string packageLocation = new DirectoryInfo(pkg).FullName; _templateCache.Scan(packageLocation); } else { _environmentSettings.Host.OnNonCriticalError("InvalidPackageSpecification", string.Format(LocalizableStrings.BadPackageSpec, pkg), null, 0); } } catch { _environmentSettings.Host.OnNonCriticalError("InvalidPackageSpecification", string.Format(LocalizableStrings.BadPackageSpec, pkg), null, 0); } } _templateCache.WriteTemplateCaches(); }