Exemplo n.º 1
0
        Task OpenReadmeFiles(
            NuGetProject nuGetProject,
            PackageIdentity package,
            NuGet.ProjectManagement.ExecutionContext executionContext,
            CancellationToken token)
        {
            //packagesPath is different for project.json vs Packages.config scenarios. So check if the project is a build-integrated project
            var buildIntegratedProject = nuGetProject as BuildIntegratedNuGetProject;
            var readmeFilePath         = String.Empty;

            if (buildIntegratedProject != null)
            {
                var packageFolderPath = BuildIntegratedProjectUtility.GetPackagePathFromGlobalSource(
                    SettingsUtility.GetGlobalPackagesFolder(settings),
                    package);

                if (Directory.Exists(packageFolderPath))
                {
                    readmeFilePath = Path.Combine(packageFolderPath, Constants.ReadmeFileName);
                }
            }
            else
            {
                var packagePath = packageManager.PackagesFolderNuGetProject.GetInstalledPackageFilePath(package);
                if (File.Exists(packagePath))
                {
                    readmeFilePath = Path.Combine(Path.GetDirectoryName(packagePath), Constants.ReadmeFileName);
                }
            }

            if (File.Exists(readmeFilePath) && !token.IsCancellationRequested)
            {
                return(executionContext.OpenFile(readmeFilePath));
            }
            return(Task.FromResult(0));
        }