public PackageConfiguration Read(FileInfo projectFile) { var nuspecFiles = projectFile.Directory .EnumerateFiles("*.nuspec", SearchOption.TopDirectoryOnly) .ToArray(); if (nuspecFiles.Length == 0) { this.logger.LogDebug("No nuspec found, skipping package configuration."); return(null); } if (nuspecFiles.Length > 1) { this.logger.LogError(@"Could not read from nuspec, multiple nuspecs found."); foreach (var item in nuspecFiles.Select(x => x.FullName)) { this.logger.LogInformation(item); } return(null); } var nuspecFile = nuspecFiles[0]; this.logger.LogInformation($"Reading package info from nuspec {nuspecFile.FullName}."); XDocument nuspec; using (var filestream = File.Open(nuspecFile.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { nuspec = XDocument.Load(filestream); } var namespaces = new XNamespace[] { "", "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd", "http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd", "http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd" }; var packageConfig = namespaces .Select(ns => ExtractPackageConfiguration(nuspec, ns)) .SingleOrDefault(config => config != null); if (packageConfig == null) { this.logger.LogError("Error reading package info from nuspec."); return(null); } packageConfig.NuspecFile = nuspecFile; return(packageConfig); }
public PackageConfiguration Read(FileInfo projectFile, IProgress <string> progress) { var nuspecFiles = projectFile.Directory .EnumerateFiles("*.nuspec", SearchOption.AllDirectories) .ToArray(); if (nuspecFiles.Length == 0) { progress.Report("No nuspec found, skipping package configuration."); return(null); } if (nuspecFiles.Length > 1) { progress.Report($@"Could not read from nuspec, multiple nuspecs found: {string.Join(Environment.NewLine, nuspecFiles.Select(x => x.FullName))}."); return(null); } var nuspecFile = nuspecFiles[0]; progress.Report($"Reading package info from nuspec {nuspecFile.FullName}."); XDocument nuspec; using (var filestream = File.Open(nuspecFile.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { nuspec = XDocument.Load(filestream); } var namespaces = new XNamespace[] { "", "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd", "http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd", "http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd" }; var packageConfig = namespaces .Select(ns => ExtractPackageConfiguration(nuspec, ns)) .SingleOrDefault(config => config != null); if (packageConfig == null) { progress.Report("Error reading package info from nuspec."); return(null); } packageConfig.NuspecFile = nuspecFile; return(packageConfig); }