From 4023d59ed949d7cc2a01e25c84c10123a370da6b Mon Sep 17 00:00:00 2001 From: Francois Retief Date: Fri, 16 Mar 2018 16:24:39 +0200 Subject: [PATCH] Support searching for NuGet.config in parent folders --- .../NugetPackageManager.cs | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/Baseclass.Contrib.Nuget.Output/Baseclass.Contrib.Nuget.Output.Build/NugetPackageManager.cs b/Baseclass.Contrib.Nuget.Output/Baseclass.Contrib.Nuget.Output.Build/NugetPackageManager.cs index dd4f33b..2ddc139 100644 --- a/Baseclass.Contrib.Nuget.Output/Baseclass.Contrib.Nuget.Output.Build/NugetPackageManager.cs +++ b/Baseclass.Contrib.Nuget.Output/Baseclass.Contrib.Nuget.Output.Build/NugetPackageManager.cs @@ -153,30 +153,34 @@ private IEnumerable GetFilteredProjectNugetPackages(NugetPackageSource c private string GetSolutionPackagePath() { - var solutionNugetConfig = Path.Combine(solutionPath, "nuget.config"); - if (File.Exists(solutionNugetConfig)) + for (var path = solutionPath; !string.IsNullOrEmpty(path); path = Path.GetDirectoryName(path)) { - var config = new XmlDocument(); - config.Load(solutionNugetConfig); + var nugetConfig = Path.Combine(path, "nuget.config"); - string repoPath = null; - var repoPathSetting = config.SelectSingleNode("/configuration/config/add[@key='repositoryPath']"); - if (repoPathSetting != null && repoPathSetting.Attributes != null) - repoPath = repoPathSetting.Attributes["value"].Value; - - if (string.IsNullOrEmpty(repoPath)) + if (File.Exists(nugetConfig)) { - repoPathSetting = config.SelectSingleNode("/configuration/settings/repositoryPath"); - if (repoPathSetting != null) - repoPath = repoPathSetting.InnerText; - } + var config = new XmlDocument(); + config.Load(nugetConfig); - if (!string.IsNullOrEmpty(repoPath)) - { - if (Path.IsPathRooted(repoPath)) - return repoPath; + string repoPath = null; + var repoPathSetting = config.SelectSingleNode("/configuration/config/add[@key='repositoryPath']"); + if (repoPathSetting != null && repoPathSetting.Attributes != null) + repoPath = repoPathSetting.Attributes["value"].Value; - return Path.GetFullPath(Path.Combine(solutionPath, repoPath)); + if (string.IsNullOrEmpty(repoPath)) + { + repoPathSetting = config.SelectSingleNode("/configuration/settings/repositoryPath"); + if (repoPathSetting != null) + repoPath = repoPathSetting.InnerText; + } + + if (!string.IsNullOrEmpty(repoPath)) + { + if (Path.IsPathRooted(repoPath)) + return repoPath; + + return Path.GetFullPath(Path.Combine(path, repoPath)); + } } }