/// <summary> /// Initializes source repositories for PowerShell cmdlets, based on config, source string, and/or host active source property value. /// </summary> /// <param name="source">The source string specified by -Source switch.</param> protected void UpdateActiveSourceRepository(string source) { var packageSources = ConsoleHost.LoadPackageSources(); // If source string is not specified, get the current active package source from the host source = ConsoleHost.GetActivePackageSource(source); if (!string.IsNullOrEmpty(source)) { // Look through all available sources (including those disabled) by matching source name and url var matchingSource = packageSources ?.Where(p => StringComparer.OrdinalIgnoreCase.Equals(p.Name, source) || StringComparer.OrdinalIgnoreCase.Equals(p.Source, source)) .FirstOrDefault(); if (matchingSource != null) { activeSourceRepository = ConsoleHost.CreateRepository(matchingSource); } else { // source should be the format of url here; otherwise it cannot resolve from name anyways. activeSourceRepository = CreateRepositoryFromSource(source); } } EnabledSourceRepositories = ConsoleHost .GetRepositories() .Where(r => r.PackageSource.IsEnabled) .ToList(); }