protected IEnumerable <Packaging.PackageReference> GetInstalledPackageReferences( string projectConfigFilePath, bool allowDuplicatePackageIds) { if (File.Exists(projectConfigFilePath)) { try { XDocument xDocument = XmlUtility.Load(projectConfigFilePath); var reader = new PackagesConfigReader(xDocument); return(reader.GetPackages(allowDuplicatePackageIds)); } catch (XmlException ex) { var message = string.Format( CultureInfo.CurrentCulture, LocalizedResourceManager.GetString("Error_PackagesConfigParseError"), projectConfigFilePath, ex.Message); throw new CommandException(message); } } return(Enumerable.Empty <Packaging.PackageReference>()); }
/// <summary> /// Given a file system path containing RedistList\FrameworkList.xml file /// return the list of assembly names read out from the XML file. /// </summary> private static List <FrameworkAssembly> GetFrameworkAssemblies(string referenceAssembliesPath) { var frameworkAssemblies = new List <FrameworkAssembly>(); try { if (FileSystemUtility.FileExists(referenceAssembliesPath, FrameworkListFileName)) { var facadeNames = GetFrameworkFacadeNames(referenceAssembliesPath); using (var stream = File.OpenRead(FileSystemUtility.GetFullPath(referenceAssembliesPath, FrameworkListFileName))) { var document = XmlUtility.Load(stream); var root = document.Root; if (root.Name.LocalName.Equals("FileList", StringComparison.OrdinalIgnoreCase)) { foreach (var element in root.Elements("File")) { var simpleAssemblyName = element.GetOptionalAttributeValue("AssemblyName"); var version = element.GetOptionalAttributeValue("Version"); if (simpleAssemblyName == null || version == null) { // Skip this file. Return an empty list // Clear frameworkAssemblies since we don't want partial results frameworkAssemblies.Clear(); break; } var assemblyName = new AssemblyName(); assemblyName.Name = simpleAssemblyName; assemblyName.Version = new Version(version); var isFacade = facadeNames.Contains(simpleAssemblyName); var frameworkAssembly = new FrameworkAssembly(assemblyName, isFacade); frameworkAssemblies.Add(frameworkAssembly); } } } } } catch { } return(frameworkAssemblies); }
public static XDocument ReadExisting(string path, ILogger log) { XDocument result = null; if (File.Exists(path)) { try { result = XmlUtility.Load(path); } catch (Exception ex) { // Log a debug message and ignore, this will force an overwrite log.LogDebug($"Failed to open imports file: {path} Error: {ex.Message}"); } } return(result); }
internal virtual XDocument LoadDocument(string path) { return(XmlUtility.Load(path, LoadOptions.PreserveWhitespace)); }