Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ public BuildAnalysis(Options options, ProgressMonitor progressMonitor)
DateTime.Now - startTime);
}

private IEnumerable<string> GetFiles(string pattern)
private IEnumerable<string> GetFiles(string pattern, bool recurseSubdirectories = true)
{
return sourceDir.GetFiles(pattern, SearchOption.AllDirectories)
return sourceDir.GetFiles(pattern, new EnumerationOptions { RecurseSubdirectories = recurseSubdirectories, MatchCasing = MatchCasing.CaseInsensitive })
.Select(d => d.FullName)
.Where(d => !options.ExcludesFile(d));
}
Expand Down Expand Up @@ -318,16 +318,16 @@ private void AnalyseProject(FileInfo project)

}

private bool Restore(string target)
private bool Restore(string target, string? pathToNugetConfig = null)
{
return dotnet.RestoreToDirectory(target, packageDirectory.DirInfo.FullName);
return dotnet.RestoreToDirectory(target, packageDirectory.DirInfo.FullName, pathToNugetConfig);
}

private void Restore(IEnumerable<string> targets)
private void Restore(IEnumerable<string> targets, string? pathToNugetConfig = null)
{
foreach (var target in targets)
{
Restore(target);
Restore(target, pathToNugetConfig);
}
}

Expand All @@ -336,7 +336,23 @@ private void DownloadMissingPackages(IEnumerable<string> restoreTargets)
var alreadyDownloadedPackages = Directory.GetDirectories(packageDirectory.DirInfo.FullName).Select(d => Path.GetFileName(d).ToLowerInvariant()).ToHashSet();
var notYetDownloadedPackages = new HashSet<string>();

var allFiles = GetFiles("*.*").ToArray();
var nugetConfigs = GetFiles("nuget.config", recurseSubdirectories: true).ToArray();
string? nugetConfig = null;
if (nugetConfigs.Length > 1)
{
progressMonitor.MultipleNugetConfig(nugetConfigs);
nugetConfig = GetFiles("nuget.config", recurseSubdirectories: false).FirstOrDefault();
if (nugetConfig == null)
{
progressMonitor.NoTopLevelNugetConfig();
}
}
else
{
nugetConfig = nugetConfigs.FirstOrDefault();
}

var allFiles = GetFiles("*.*");
foreach (var file in allFiles)
{
try
Expand Down Expand Up @@ -390,7 +406,7 @@ private void DownloadMissingPackages(IEnumerable<string> restoreTargets)
continue;
}

success = Restore(tempDir.DirInfo.FullName);
success = Restore(tempDir.DirInfo.FullName, nugetConfig);

// TODO: the restore might fail, we could retry with a prerelease (*-* instead of *) version of the package.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ private bool RunCommand(string args)
return true;
}

public bool RestoreToDirectory(string projectOrSolutionFile, string packageDirectory)
public bool RestoreToDirectory(string projectOrSolutionFile, string packageDirectory, string? pathToNugetConfig = null)
{
var args = $"restore --no-dependencies \"{projectOrSolutionFile}\" --packages \"{packageDirectory}\" /p:DisableImplicitNuGetFallbackFolder=true";
if (pathToNugetConfig != null)
args += $" --configfile \"{pathToNugetConfig}\"";
return RunCommand(args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,15 @@ public void FailedToReadFile(string file, Exception ex)
logger.Log(Severity.Info, $"Failed to read file {file}");
logger.Log(Severity.Debug, $"Failed to read file {file}, exception: {ex}");
}

public void MultipleNugetConfig(string[] nugetConfigs)
{
logger.Log(Severity.Info, $"Found multiple nuget.config files: {string.Join(", ", nugetConfigs)}.");
}

internal void NoTopLevelNugetConfig()
{
logger.Log(Severity.Info, $"Could not find a top-level nuget.config file.");
}
}
}