示例#1
0
        private IEnumerable <PackageDependency> GetPackageDependenciesFromRepositoriesConfig(TeamProject teamProject, Item repository)
        {
            List <PackageDependency> repositoryDependencies = new List <PackageDependency>();

            Stream               repoFileStream               = repository.DownloadFile();
            XDocument            repoXml                      = XDocument.Load(repoFileStream);
            IEnumerable <string> relativePackageConfigPaths   = configInterpreter.GetRelativePackagesConfigPathsFromRepositoriesConfig(repoXml);
            string               repositoriesConfigServerPath = repository.ServerItem;
            int    repositoriesConfigLength                   = repositoriesConfigFileName.Length;
            string packageConfigFolderServerPath              = repositoriesConfigServerPath.Remove(repositoriesConfigServerPath.Length - repositoriesConfigLength, repositoriesConfigLength);

            foreach (string packageConfigPathRelativeToRepositoriesConfig in relativePackageConfigPaths)
            {
                // navigate to the folder server path for the repositories.config file
                string repositoryNodeServerItem = tfsServerPathTranslator.GetServerPath(packageConfigFolderServerPath, packageConfigPathRelativeToRepositoriesConfig);
                Item   packageConfig            = teamProject.VersionControlServer.GetItem(repositoryNodeServerItem);
                if (packageConfig != null)
                {
                    Stream    packagesConfigStream = packageConfig.DownloadFile();
                    XDocument packagesConfigXml    = XDocument.Load(packagesConfigStream);
                    IEnumerable <PackageDependency> packageDependencies = configInterpreter.GetPackageDependenciesFromPackagesConfig(packagesConfigXml);
                    foreach (PackageDependency packageDependency in packageDependencies)
                    {
                        if (repositoryDependencies.Where(dp => dp.Id == packageDependency.Id && dp.VersionSpec == packageDependency.VersionSpec).FirstOrDefault() == null)
                        {
                            repositoryDependencies.Add(packageDependency);
                        }
                    }
                }
            }

            return(repositoryDependencies);
        }
示例#2
0
        internal void AnalyzePackagesRepository(FileInfo solution, bool verbose)
        {
            if (solution.Directory == null)
            {
                return;
            }

            //TODO: packages path might be configurable
            string repositoriesConfigPath = Path.Combine(solution.Directory.FullName, @"packages\repositories.config");

            if (File.Exists(repositoriesConfigPath))
            {
                FileInfo             repositoriesConfig = new FileInfo(repositoriesConfigPath);
                IEnumerable <string> relativePackagesConfigPaths;
                using (var repositoriesConfigStream = File.OpenRead(repositoriesConfig.FullName))
                {
                    relativePackagesConfigPaths =
                        configInterpreter.GetRelativePackagesConfigPathsFromRepositoriesConfig(
                            XDocument.Load(repositoriesConfigStream));
                }

                if (relativePackagesConfigPaths != null)
                {
                    foreach (string relativePackagesConfigPath in relativePackagesConfigPaths)
                    {
                        FileInfo packagesConfig = fileSystemPathTranslator.GetAbsolutePath(repositoriesConfig, relativePackagesConfigPath);
                        string   projectName    = GetProjectNameForPackagesConfig(solution, repositoriesConfig, packagesConfig);
                        if (!string.IsNullOrWhiteSpace(projectName))
                        {
                            if (verbose)
                            {
                                ConsolePrinter.Log(" -- Project '{0}' in folder '{1}'", projectName, packagesConfig.DirectoryName);
                            }
                            else
                            {
                                ConsolePrinter.Log(" -- Project '{0}'", projectName);
                            }
                        }

                        using (var packagesConfigStream = File.OpenRead(packagesConfig.FullName))
                        {
                            IEnumerable <PackageDependency> packageDependencies =
                                configInterpreter.GetPackageDependenciesFromPackagesConfig(XDocument.Load(packagesConfigStream));
                            ConsolePrinter.PrintPackageDependenciesForProject(packageDependencies, verbose);
                        }
                    }
                }
            }
        }