Example #1
0
        public IEnumerable <LockFileTargetLibrary> GetRuntimeLibraries(IEnumerable <string> excludeFromPublishPackageIds)
        {
            IEnumerable <LockFileTargetLibrary>        runtimeLibraries = _lockFileTarget.Libraries;
            Dictionary <string, LockFileTargetLibrary> libraryLookup    =
                runtimeLibraries.ToDictionary(e => e.Name, StringComparer.OrdinalIgnoreCase);

            HashSet <string> allExclusionList = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            if (IsFrameworkDependent && PlatformLibrary != null)
            {
                allExclusionList.UnionWith(_lockFileTarget.GetPlatformExclusionList(PlatformLibrary, libraryLookup));

                // If the platform library is not Microsoft.NETCore.App, treat it as an implicit dependency.
                // This makes it so Microsoft.AspNet.* 2.x platforms also exclude Microsoft.NETCore.App files.
                if (PlatformLibrary.Name.Length > 0 && !String.Equals(PlatformLibrary.Name, NetCorePlatformLibrary, StringComparison.OrdinalIgnoreCase))
                {
                    var library = _lockFileTarget.GetLibrary(NetCorePlatformLibrary);
                    if (library != null)
                    {
                        allExclusionList.UnionWith(_lockFileTarget.GetPlatformExclusionList(library, libraryLookup));
                    }
                }
            }

            if (excludeFromPublishPackageIds?.Any() == true)
            {
                HashSet <string> excludeFromPublishList =
                    GetExcludeFromPublishList(
                        excludeFromPublishPackageIds,
                        libraryLookup);

                allExclusionList.UnionWith(excludeFromPublishList);
            }

            if (PackagesToBeFiltered != null)
            {
                var filterLookup = new Dictionary <string, HashSet <PackageIdentity> >(StringComparer.OrdinalIgnoreCase);
                foreach (var pkg in PackagesToBeFiltered)
                {
                    HashSet <PackageIdentity> packageinfos;
                    if (filterLookup.TryGetValue(pkg.Id, out packageinfos))
                    {
                        packageinfos.Add(pkg);
                    }
                    else
                    {
                        packageinfos = new HashSet <PackageIdentity>();
                        packageinfos.Add(pkg);
                        filterLookup.Add(pkg.Id, packageinfos);
                    }
                }

                allExclusionList.UnionWith(GetPackagesToBeFiltered(filterLookup, libraryLookup));
            }

            return(runtimeLibraries.Filter(allExclusionList).ToArray());
        }
Example #2
0
        public static ProjectContext CreateProjectContext(
            this LockFile lockFile,
            NuGetFramework framework,
            string runtime,
            string platformLibraryName,
            bool isSelfContained)
        {
            if (lockFile == null)
            {
                throw new ArgumentNullException(nameof(lockFile));
            }
            if (framework == null)
            {
                throw new ArgumentNullException(nameof(framework));
            }

            LockFileTarget lockFileTarget = lockFile.GetTarget(framework, runtime);

            if (lockFileTarget == null)
            {
                string frameworkString = framework.DotNetFrameworkName;
                string targetMoniker   = string.IsNullOrEmpty(runtime) ?
                                         frameworkString :
                                         $"{frameworkString}/{runtime}";

                throw new BuildErrorException(Strings.AssetsFileMissingTarget, lockFile.Path, targetMoniker, framework.GetShortFolderName(), runtime);
            }

            LockFileTargetLibrary platformLibrary = lockFileTarget.GetLibrary(platformLibraryName);
            bool isFrameworkDependent             = platformLibrary != null && (!isSelfContained || string.IsNullOrEmpty(lockFileTarget.RuntimeIdentifier));

            return(new ProjectContext(lockFile, lockFileTarget, platformLibrary, isFrameworkDependent));
        }
Example #3
0
        public ProjectContext(LockFile lockFile, LockFileTarget lockFileTarget, string platformLibraryName)
        {
            _lockFile            = lockFile;
            _lockFileTarget      = lockFileTarget;
            _platformLibraryName = platformLibraryName;

            PlatformLibrary = _lockFileTarget.GetLibrary(_platformLibraryName);
            IsPortable      = PlatformLibrary != null && string.IsNullOrEmpty(_lockFileTarget.RuntimeIdentifier);
        }
Example #4
0
        internal IEnumerable <PackageIdentity> GetTransitiveList(string package)
        {
            LockFileTargetLibrary platformLibrary = _lockFileTarget.GetLibrary(package);
            IEnumerable <LockFileTargetLibrary>        runtimeLibraries = _lockFileTarget.Libraries;
            Dictionary <string, LockFileTargetLibrary> libraryLookup    =
                runtimeLibraries.ToDictionary(e => e.Name, StringComparer.OrdinalIgnoreCase);

            return(_lockFileTarget.GetTransitivePackagesList(platformLibrary, libraryLookup));
        }