Ejemplo n.º 1
0
        private async Task ApplyPackageInformationToProjectReference(ProjectReference projectReference, PackageList packageList, string csProjPath)
        {
            projectReference.ReferenceType = ReferenceType.PackageReference;

            var fileInfo = new FileInfo(Path.Combine(csProjPath, projectReference.Location));

            if (fileInfo.Exists)
            {
                var directory = fileInfo.Directory;
                int position  = 0;
                while (position < 3 && directory != null)
                {
                    var licenseFiles = directory.GetFiles("*license*");
                    var nupkgFiles   = directory.GetFiles("*.nupkg");

                    if (nupkgFiles?.Any() == true)
                    {
                        projectReference.NugetPackage = await GetNugetPackageInformation(nupkgFiles[0]);
                    }

                    if (licenseFiles?.Any() == true)
                    {
                        projectReference.LicenseFiles = await GetLicenses(licenseFiles);
                    }

                    directory = directory.Parent;
                    position++;
                }

                if (projectReference.NugetPackage != null)
                {
                    projectReference.Package = packageList.GetPackageByName(projectReference.NugetPackage.Id);
                }
            }
        }