예제 #1
0
        /// <summary>Returns the referenced .dll/.exe file paths</summary>
        public static IEnumerable <FilePath> GetReferencedAssembliesFilePaths(
            this NuGetPackage pkg,
            FolderNuGetProject project,
            NuGetFramework targetFramework)
        {
            if (pkg == null)
            {
                yield break;
            }

            var pkgPath       = pkg.GetPackageDirectoryPath(project);
            var archiveReader = pkg.GetArchiveReader(project);

            var referenceItems = archiveReader.GetReferenceItems().ToList();
            var referenceGroup = SelectFrameworkMostCompatibleGroup(targetFramework, referenceItems);

            if (referenceGroup != null)
            {
                LogTo.Trace(
                    $"Found compatible reference group {referenceGroup.TargetFramework.DotNetFrameworkName} for package {pkg.Identity}");

                foreach (FilePath assemblyPath in referenceGroup.Items
                         .Select(x => new FilePath(x))
                         .Where(x => x.Extension == ".dll" || x.Extension == ".exe")
                         .Select(pkgPath.CombineFile))
                {
                    LogTo.Trace($"Found NuGet reference {assemblyPath} from package {pkg.Identity}");

                    yield return(assemblyPath);
                }
            }
            else if (referenceItems.Count == 0)
            {
                // Only show a verbose message if there were no reference items (I.e., it's probably a content-only package or a metapackage and not a mismatch)
                LogTo.Trace($"Could not find any reference items in package {pkg.Identity}");
            }
            else
            {
                LogTo.Trace(
                    $"Could not find compatible reference group for package {pkg.Identity} (found {string.Join((string)",", (IEnumerable<string>)referenceItems.Select(x => x.TargetFramework.DotNetFrameworkName))})");
            }
        }
예제 #2
0
        public static IEnumerable <DirectoryPath> GetContentDirectoryPath(
            this NuGetPackage pkg,
            FolderNuGetProject project,
            NuGetFramework targetFramework)
        {
            if (pkg == null)
            {
                yield break;
            }

            var pkgPath = pkg.GetPackageDirectoryPath(project);

            if (pkgPath == null)
            {
                yield break;
            }

            var archiveReader = pkg.GetArchiveReader(project);

            if (archiveReader == null)
            {
                yield break;
            }

            FrameworkSpecificGroup contentGroup = SelectFrameworkMostCompatibleGroup(targetFramework, archiveReader.GetContentItems().ToList());

            if (contentGroup != null)
            {
                foreach (DirectoryPath contentPath in contentGroup.Items.Select(x => new FilePath(x).Segments[0])
                         .Distinct()
                         .Select(x => pkgPath.Combine(x)))
                {
                    LogTo.Trace(
                        $"Found content path {contentPath} from compatible content group {contentGroup.TargetFramework.DotNetFrameworkName} from package {pkg.Identity}");

                    yield return(contentPath);
                }
            }
        }