Skip to content
Open
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
23 changes: 21 additions & 2 deletions src/assembly-differ/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ internal static class Program
private static SuggestedVersionChange _preventChange = SuggestedVersionChange.None;
private static bool _allowEmptyPreviousNuget = false;

private static readonly NuGetInstallerOptions _nugetInstallerOptions = new NuGetInstallerOptions();

private static HashSet<string> Targets { get; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

private static int Main(string[] args)
{
var providers = new AssemblyProviderFactoryCollection(
new AssemblyProviderFactory(),
new DirectoryAssemblyProviderFactory(),
new NuGetAssemblyProviderFactory(new Providers.NuGet.NuGet()),
new PreviousNuGetAssemblyProviderFactory(new PreviousNugetLocator()),
new NuGetAssemblyProviderFactory(new Providers.NuGet.NuGet(_nugetInstallerOptions)),
new PreviousNuGetAssemblyProviderFactory(new PreviousNugetLocator(_nugetInstallerOptions)),
new GitHubAssemblyProviderFactory(new Git(Environment.GetEnvironmentVariable("GIT")))
);

Expand All @@ -49,6 +51,8 @@ private static int Main(string[] args)
c => _preventChange = Enum.Parse<SuggestedVersionChange>(c, true)},
{"a|allow-empty-previous-nuget=", "",
n => _allowEmptyPreviousNuget = n != null},
{"c|nuget-config-dir=", "the search directory for NuGet to find a NuGet.config file. Defaults to `null` which will use the root config. Use only if using NuGet as a provider.",
c => SetNugetConfigSearchDirectory(c) },
{"h|?|help", "show this message and exit", h => _help = h != null},
};

Expand Down Expand Up @@ -165,6 +169,21 @@ private static void AddTarget(string input)
Targets.Add(part);
}

private static void SetNugetConfigSearchDirectory(string searchDirectory)
{
if (string.IsNullOrEmpty(searchDirectory))
{
throw new ArgumentException("Cannot be null or empty", nameof(searchDirectory));
}

if (!Directory.Exists(searchDirectory))
{
throw new DirectoryNotFoundException($"Could not find directory from supplied value of '{searchDirectory}'.");
}

_nugetInstallerOptions.NuGetConfigSearchDirectory = searchDirectory;
}

private static void ShowHelp(OptionSet options, AssemblyProviderFactoryCollection providerFactoryCollection)
{
Console.ForegroundColor = ConsoleColor.Green;
Expand Down
12 changes: 11 additions & 1 deletion src/assembly-differ/Providers/NuGet/NuGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@ public interface INuGet
NuGetPackage InstallPackage(string packageName, string version, string targetDirectory);
}

public class NuGetInstallerOptions
{
public string NuGetConfigSearchDirectory { get; set; }
}

public class NuGet : INuGet
{
protected NuGetInstallerOptions Options { get; }

public NuGet(NuGetInstallerOptions options)
=> Options = options;

public virtual NuGetPackage InstallPackage(string packageName, string version, string targetDirectory)
{
if (!Directory.Exists(targetDirectory)) Directory.CreateDirectory(targetDirectory);

var packageVersion = NuGetVersion.Parse(version);
var nuGetFramework = NuGetFramework.AnyFramework;
var settings = Settings.LoadDefaultSettings(root: null);
var settings = Settings.LoadDefaultSettings(root: Options?.NuGetConfigSearchDirectory);
var sourceRepositoryProvider = new SourceRepositoryProvider(
new PackageSourceProvider(settings), Repository.Provider.GetCoreV3());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace Differ.Providers.PreviousNuGet
{
public class PreviousNugetLocator : Differ.Providers.NuGet.NuGet
{
public PreviousNugetLocator(NuGetInstallerOptions options) : base(options)
{}

public override NuGetPackage InstallPackage(string packageName, string currentVersion, string targetDirectory)
{
var nugetVersion = new NuGetVersion(currentVersion);
Expand Down