示例#1
0
 public NugetRepositoryEntry(LocalPackageSourceInfo localPackageSourceInfo,
                             List <FrameworkSpecificGroup> refItemGroups          = null,
                             List <FrameworkSpecificGroup> runtimeItemGroups      = null,
                             List <FrameworkSpecificGroup> debugRuntimeItemGroups = null,
                             List <FrameworkSpecificGroup> contentFileGroups      = null,
                             List <FrameworkSpecificGroup> analyzerItemGroups     = null,
                             List <PackageDependencyGroup> dependencyGroups       = null)
 {
     LocalPackageSourceInfo = localPackageSourceInfo;
     RefItemGroups          = refItemGroups ?? new List <FrameworkSpecificGroup>();
     RuntimeItemGroups      = runtimeItemGroups ?? new List <FrameworkSpecificGroup>();
     DebugRuntimeItemGroups = debugRuntimeItemGroups ?? new List <FrameworkSpecificGroup>();
     ContentFileGroups      = contentFileGroups ?? new List <FrameworkSpecificGroup>();
     AnalyzerItemGroups     = analyzerItemGroups ?? new List <FrameworkSpecificGroup>();
     DependencyGroups       = dependencyGroups ?? new List <PackageDependencyGroup>();
 }
        public NugetRepositoryEntry ResolveGroups(LocalPackageSourceInfo localPackageSourceInfo)
        {
            var collection = new ContentItemCollection();

            collection.Load(localPackageSourceInfo.Package.Files);
            var allPackageDependencyGroups = localPackageSourceInfo.Package.Nuspec.GetDependencyGroups().ToArray();
            var frameworkReferenceGroups   = localPackageSourceInfo.Package.Nuspec.GetFrameworkRefGroups().ToArray();

            var entry = new NugetRepositoryEntry(localPackageSourceInfo);

            foreach (var target in _targets)
            {
                SelectionCriteria criteria = _conventions.Criteria.ForFrameworkAndRuntime(target.Framework, target.RuntimeIdentifier);

                // The nunit3testadapter package publishes dll's in build/
                var buildAssemblies = new PatternSet(_conventions.Properties, new[]
                {
                    new PatternDefinition("build/{tfm}/{any?}"),
                    new PatternDefinition("build/{assembly?}")
                }, new[]
                {
                    new PatternDefinition("build/{tfm}/{assembly}"),
                    new PatternDefinition("build/{assembly}")
                });

                // shipped debug binaries
                var netcoreappdebugAssemblies = new PatternSet(_conventions.Properties, new[]
                {
                    new PatternDefinition("netcoreappdebug/{tfm}/{any?}"),
                    new PatternDefinition("netcoreappdebug/{assembly?}")
                }, new[]
                {
                    new PatternDefinition("netcoreappdebug/{tfm}/{assembly}"),
                    new PatternDefinition("netcoreappdebug/{assembly}")
                });

                // The analyzer dll's are published in analyzers/ or analyzers/dotnet/cs/
                var analyzerAssemblies = new PatternSet(_conventions.Properties, new []
                {
                    new PatternDefinition("analyzers/dotnet/cs/{assembly?}"),
                    new PatternDefinition("analyzers/{assembly?}")
                }, new []
                {
                    new PatternDefinition("analyzers/dotnet/cs/{assembly}"),
                    new PatternDefinition("analyzers/{assembly}")
                });

                AddIfNotNull(entry.RefItemGroups, target.Framework,
                             collection.FindBestItemGroup(criteria,
                                                          _conventions.Patterns.CompileRefAssemblies,
                                                          _conventions.Patterns.CompileLibAssemblies)
                             ?.Items);

                AddIfNotNull(entry.RuntimeItemGroups, target.Framework,
                             collection.FindBestItemGroup(criteria,
                                                          _conventions.Patterns.RuntimeAssemblies,
                                                          _conventions.Patterns.NativeLibraries,
                                                          buildAssemblies)
                             ?.Items.Where(IsDll));

                AddIfNotNull(entry.DebugRuntimeItemGroups, target.Framework,
                             collection.FindItemGroups(netcoreappdebugAssemblies)
                             .SingleOrDefault()
                             ?.Items.Where(IsDll));

                AddIfNotNull(entry.ContentFileGroups, target.Framework,
                             collection.FindBestItemGroup(criteria,
                                                          _conventions.Patterns.ContentFiles)
                             ?.Items);

                AddIfNotNull(entry.AnalyzerItemGroups, target.Framework,
                             collection.FindItemGroups(analyzerAssemblies)
                             .SingleOrDefault()
                             ?.Items);

                // Merge FrameworkReferences with normal PackageReferences
                var dependencies = NuGetFrameworkUtility.GetNearest(allPackageDependencyGroups, target.Framework);
                var frameworks   = NuGetFrameworkUtility.GetNearest(frameworkReferenceGroups, target.Framework);

                if (dependencies != null || frameworks != null)
                {
                    entry.DependencyGroups.Add(new PackageDependencyGroup(
                                                   dependencies?.TargetFramework ?? frameworks?.TargetFramework,
                                                   new[]
                    {
                        frameworks?.FrameworkReferences.Select(FrameworkDependencyResolver.ConvertToDependency),
                        dependencies?.Packages,
                    }
                                                   .SelectMany(v => v ?? Array.Empty <PackageDependency>())));
                }
            }

            return(entry);
 private NugetRepositoryEntry BuildEntry(
     LocalPackageSourceInfo targetPackage,
     string targetFramework,
     Dictionary <string, (string file, Version version)> frameworkList,