public IEnumerable <VersionUpdateResult> UpdateVersionInProject(string projectFile, string nameFilter, string versionFilter, string newVersion, bool suppressPrompt = false) { var doc = XDocument.Parse(File.ReadAllText(projectFile)); var items = new PackageReferenceXmlReader(doc) .GetPackageReferenceElements(nameFilter, versionFilter); if (!items.Any()) { return(null); } var pr = _mapper.Map(items); // ok lets provide confirmation _renderer.RenderProjectResults(0, _renderer.GetMaxNumPad(pr), projectFile, pr); if (!suppressPrompt) { ConsoleRender.W($"Are you sure you want to change versions for {pr.Count()} packages to ") .W($"{newVersion}", ConsoleColor.DarkMagenta).W(" ? Y/N: "); var inp = Console.ReadLine(); if (!inp.Equals("Y", StringComparison.InvariantCultureIgnoreCase)) { return(null); } } return(_packageReferenceUpdater.UpdateVersion(projectFile, nameFilter, versionFilter, newVersion)); }
public bool SetNugetPackageVersions(SearchQueryFilter filter, string setVersion, IEnumerable <ProjectFile> projFiles, string strPad, ProjectNugetVersionUpdater tools) { var nameFilter = filter.Name; var versionFilter = filter.Version; var numProjectFiles = projFiles.Count(); if (numProjectFiles < 1) { ConsoleRender.W("No file(s) matching spec:") .W($"\n{strPad}Name : {nameFilter}") .W($"\n{strPad}Version : {versionFilter}\n"); return(true); } ConsoleRender.W($"Are you sure you want to change versions for {numProjectFiles} project files to ") .W($"{setVersion}", ConsoleColor.DarkMagenta).W(" ? Y/N: "); var inp = Console.ReadLine(); if (!inp.Equals("Y", StringComparison.InvariantCultureIgnoreCase)) { return(true); } // update versions tools.UpdateVersionInProjects(projFiles, nameFilter, versionFilter, setVersion, true); ConsoleRender.W($"Updated {numProjectFiles} projects with packages to version {setVersion}"); return(false); }