private void ActOnProject(Config config, string filePath) { Vlog(filePath); var(document, itemGroups) = ProjectFileHelper.LoadProjectXml(filePath); var shouldSave = ActOnProject(config, ref itemGroups); if (shouldSave) { var originalBytes = File.ReadAllBytes(filePath); byte[] newBytes = null; using (var memoryStream = new MemoryStream()) using (var textWriter = new StreamWriter(memoryStream, Encoding.UTF8)) { document.Save(textWriter, SaveOptions.None); newBytes = memoryStream.ToArray(); } newBytes = SyncBOM(originalBytes, newBytes); if (!AreEqual(originalBytes, newBytes)) { File.WriteAllBytes(filePath, newBytes); } } }
public List <DepReference> GetPackageReferencesFromProjectFile(string projectPath) { var packageRefs = new List <DepReference>(); var(document, itemGroups) = ProjectFileHelper.LoadProjectXml(projectPath); var refItemGroup = itemGroups.FirstOrDefault(HasReference); var refsOnly = refItemGroup?.Descendants()?.Where(IsReference); if (refsOnly?.Any() == true) { foreach (var @ref in refsOnly) { string hintPath = @ref.Descendants()?.FirstOrDefault(IsHintPath)?.Value; string packageIncludeString = @ref.Attributes().FirstOrDefault(a => a.Name == "Include")?.Value; if (packageIncludeString != null) { var packageRef = new DepReference(packageIncludeString, hintPath); packageRefs.Add(packageRef); } } } return(packageRefs); }