コード例 #1
0
        public int Execute()
        {
            // Most of this code is from NuGet, just some refactoring for our system.
            // Collect config
            var config = NuGetConfig.ForSolution(TargetDirectory);

            var sources = config.Sources.LoadPackageSources();

            if (!sources.Any())
            {
                Reports.Information.WriteLine("No sources found.");
            }
            else
            {
                Reports.Information.WriteLine("Feeds in use:");

                // Iterate over the sources and report them
                foreach (var source in sources)
                {
                    var enabledString = source.IsEnabled ? "" : " [Disabled]";

                    var line = $"    {source.Source}{enabledString.Yellow().Bold()}";
                    Reports.Information.WriteLine(line);

                    var origin = source.Origin as Settings;
                    if (origin != null)
                    {
                        Reports.Information.WriteLine($"      Origin: {origin.ConfigFilePath}");
                    }
                    else if (source.IsOfficial)
                    {
                        Reports.Information.WriteLine($"      Offical NuGet Source, enabled by default");
                    }
                }
            }

            // Display config files in use
            var settings = config.Settings as Settings;

            if (settings != null)
            {
                var configFiles = settings.GetConfigFiles();

                Reports.Quiet.WriteLine($"{Environment.NewLine}NuGet Config files in use:");
                foreach (var file in configFiles)
                {
                    Reports.Quiet.WriteLine($"    {file}");
                }
            }
            return(0);
        }
コード例 #2
0
        private async Task <Tuple <string, string> > ResolvePackageIdAndVersion(string packageId, string packageVersion)
        {
            if (string.IsNullOrEmpty(packageId))
            {
                return(null);
            }

            // For nupkgs, get the id and version from the package
            if (packageId.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase))
            {
                if (!File.Exists(packageId))
                {
                    WriteError(string.Format("Could not find the file {0}.", packageId));
                    return(null);
                }

                var packagePath      = Path.GetFullPath(packageId);
                var packageDirectory = Path.GetDirectoryName(packagePath);
                var zipPackage       = new NuGet.ZipPackage(packagePath);
                FeedOptions.FallbackSources.Add(packageDirectory);

                return(new Tuple <string, string>(
                           zipPackage.Id,
                           zipPackage.Version.ToString()));
            }

            // If the version is missing, try to find the latest version
            if (string.IsNullOrEmpty(packageVersion))
            {
                var rootDirectory = ProjectResolver.ResolveRootDirectory(_commandsRepository.Root.Root);
                var config        = NuGetConfig.ForSolution(rootDirectory, RestoreCommand.FileSystem);

                var packageFeeds = new List <IPackageFeed>();

                var effectiveSources = PackageSourceUtils.GetEffectivePackageSources(
                    config.Sources,
                    FeedOptions.Sources,
                    FeedOptions.FallbackSources);

                foreach (var source in effectiveSources)
                {
                    var feed = PackageSourceUtils.CreatePackageFeed(
                        source,
                        FeedOptions.NoCache,
                        FeedOptions.IgnoreFailedSources,
                        Reports);
                    if (feed != null)
                    {
                        packageFeeds.Add(feed);
                    }
                }

                var package = await PackageSourceUtils.FindLatestPackage(packageFeeds, packageId);

                if (package == null)
                {
                    Reports.Error.WriteLine("Unable to locate the package {0}".Red(), packageId);
                    return(null);
                }

                return(new Tuple <string, string>(
                           packageId,
                           package.Version.ToString()));
            }

            // Otherwise, just assume that what you got is correct
            return(new Tuple <string, string>(packageId, packageVersion));
        }
コード例 #3
0
 private void ReadSettings(string solutionDirectory)
 {
     Config = NuGetConfig.ForSolution(solutionDirectory, FileSystem);
 }