コード例 #1
0
        public static LockFileTargetLibrary CreateLockFileTargetLibrary(
            LockFileLibrary library,
            LocalPackageInfo package,
            RestoreTargetGraph targetGraph,
            LibraryIncludeFlags dependencyType,
            NuGetFramework targetFrameworkOverride,
            IEnumerable <LibraryDependency> dependencies,
            LockFileBuilderCache cache)
        {
            LockFileTargetLibrary lockFileLib = null;
            var runtimeIdentifier             = targetGraph.RuntimeIdentifier;
            var framework = targetFrameworkOverride ?? targetGraph.Framework;

            var orderedCriteriaSets = cache.GetSelectionCriteria(targetGraph, framework);
            var contentItems        = cache.GetContentItems(library, package);

            // This will throw an appropriate error if the nuspec is missing
            var nuspec = package.Nuspec;

            for (var i = 0; i < orderedCriteriaSets.Count; i++)
            {
                // Create a new library each time to avoid
                // assets being added from other criteria.
                lockFileLib = new LockFileTargetLibrary()
                {
                    Name    = package.Id,
                    Version = package.Version,
                    Type    = LibraryType.Package
                };

                // Populate assets
                AddAssets(library, package, targetGraph, dependencyType, lockFileLib, framework, runtimeIdentifier, contentItems, nuspec, orderedCriteriaSets[i]);

                // Check if compatile assets were found.
                // If no compatible assets were found and this is the last check
                // continue on with what was given, this will fail in the normal
                // compat verification.
                if (CompatibilityChecker.HasCompatibleAssets(lockFileLib))
                {
                    // Stop when compatible assets are found.
                    break;
                }
            }

            // Add dependencies
            AddDependencies(dependencies, lockFileLib, framework, nuspec);

            // Exclude items
            ExcludeItems(lockFileLib, dependencyType);

            return(lockFileLib);
        }
コード例 #2
0
ファイル: LockFileUtils.cs プロジェクト: eriawan/NuGet.Client
        /// <summary>
        /// Create a lock file target library for the given <paramref name="library"/>
        /// </summary>
        /// <param name="aliases">When an alias is specified, all assemblies coming from the library will need to be referenced with an alias.</param>
        /// <param name="library">The lock file library, expected to be for the equivalent package as <paramref name="library"/> and <paramref name="package"/>. </param>
        /// <param name="package">The local package info.</param>
        /// <param name="targetGraph">The target graph for which the asset selection needs to happen.</param>
        /// <param name="dependencyType">The resolved dependency type.</param>
        /// <param name="targetFrameworkOverride">The original framework if the asset selection is happening for a fallback framework.</param>
        /// <param name="dependencies">The dependencies of this package.</param>
        /// <param name="cache">The lock file build cache.</param>
        /// <returns>The LockFileTargetLibrary</returns>
        internal static LockFileTargetLibrary CreateLockFileTargetLibrary(
            string aliases,
            LockFileLibrary library,
            LocalPackageInfo package,
            RestoreTargetGraph targetGraph,
            LibraryIncludeFlags dependencyType,
            NuGetFramework targetFrameworkOverride,
            List <LibraryDependency> dependencies,
            LockFileBuilderCache cache,
            MaccatalystFallback maccatalystFallback)
        {
            var runtimeIdentifier = targetGraph.RuntimeIdentifier;
            var framework         = targetFrameworkOverride ?? targetGraph.Framework;

            return(cache.GetLockFileTargetLibrary(targetGraph, framework, package, aliases, dependencyType,
                                                  () =>
            {
                LockFileTargetLibrary lockFileLib = null;
                // This will throw an appropriate error if the nuspec is missing
                var nuspec = package.Nuspec;

                var orderedCriteriaSets = cache.GetSelectionCriteria(targetGraph, framework);
                var contentItems = cache.GetContentItems(library, package);

                var packageTypes = nuspec.GetPackageTypes().AsList();

                for (var i = 0; i < orderedCriteriaSets.Count; i++)
                {
                    // Create a new library each time to avoid
                    // assets being added from other criteria.
                    lockFileLib = new LockFileTargetLibrary()
                    {
                        Name = package.Id,
                        Version = package.Version,
                        Type = LibraryType.Package,
                        PackageType = packageTypes
                    };

                    // Populate assets

                    if (lockFileLib.PackageType.Contains(PackageType.DotnetTool))
                    {
                        AddToolsAssets(library, package, targetGraph, dependencyType, lockFileLib, framework,
                                       runtimeIdentifier, contentItems, nuspec, orderedCriteriaSets[i], maccatalystFallback);
                        if (CompatibilityChecker.HasCompatibleToolsAssets(lockFileLib))
                        {
                            break;
                        }
                    }
                    else
                    {
                        AddAssets(aliases, library, package, targetGraph, dependencyType, lockFileLib,
                                  framework, runtimeIdentifier, contentItems, nuspec, orderedCriteriaSets[i], maccatalystFallback);
                        // Check if compatible assets were found.
                        // If no compatible assets were found and this is the last check
                        // continue on with what was given, this will fail in the normal
                        // compat verification.
                        if (CompatibilityChecker.HasCompatibleAssets(lockFileLib))
                        {
                            // Stop when compatible assets are found.
                            break;
                        }
                    }
                }

                // Add dependencies
                AddDependencies(dependencies, lockFileLib, framework, nuspec, maccatalystFallback);

                // Exclude items
                ExcludeItems(lockFileLib, dependencyType);

                return lockFileLib;
            }));
        }