Exemple #1
0
        public void ContentModel_LibRootFolderOnly()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var collection = new ContentItemCollection();

            collection.Load(new string[]
            {
                "lib/a.dll"
            });

            // Act
            List <ContentItemGroup> groups = new();

            collection.PopulateItemGroups(conventions.Patterns.RuntimeAssemblies, groups);

            // Assert
            Assert.Equal(1, groups.Count);
            Assert.Equal(NuGetFramework.Parse("net"), groups[0].Properties["tfm"]);
        }
Exemple #2
0
        public void ContentModel_LibRootAndTFM()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var collection = new ContentItemCollection();

            collection.Load(new string[]
            {
                "lib/net46/a.dll",
                "lib/a.dll",
            });

            // Act
            List <ContentItemGroup> itemGroups = new();

            collection.PopulateItemGroups(conventions.Patterns.RuntimeAssemblies, itemGroups);
            var groups = itemGroups
                         .OrderBy(group => ((NuGetFramework)group.Properties["tfm"]).GetShortFolderName())
                         .ToList();

            // Assert
            Assert.Equal(2, groups.Count);
            Assert.Equal(NuGetFramework.Parse("net"), groups[0].Properties["tfm"]);
            Assert.Equal(NuGetFramework.Parse("net46"), groups[1].Properties["tfm"]);
        }
        private static HashSet <FrameworkRuntimePair> GetAvailableFrameworkRuntimePairs(CompatibilityData compatibilityData, RestoreTargetGraph graph)
        {
            var available = new HashSet <FrameworkRuntimePair>();

            var contentItems = new ContentItemCollection();

            contentItems.Load(compatibilityData.Files);

            List <ContentItemGroup> itemGroups = new List <ContentItemGroup>();

            if (compatibilityData.TargetLibrary.PackageType.Contains(PackageType.DotnetTool))
            {
                contentItems.PopulateItemGroups(graph.Conventions.Patterns.ToolsAssemblies, itemGroups);
                foreach (var group in itemGroups)
                {
                    group.Properties.TryGetValue(ManagedCodeConventions.PropertyNames.RuntimeIdentifier, out var ridObj);
                    group.Properties.TryGetValue(ManagedCodeConventions.PropertyNames.TargetFrameworkMoniker, out var tfmObj);

                    var tfm = tfmObj as NuGetFramework;
                    var rid = ridObj as string;
                    if (tfm?.IsSpecificFramework == true)
                    {
                        available.Add(new FrameworkRuntimePair(tfm, rid));
                    }
                }
            }

            return(available);
        }
Exemple #4
0
        public void ContentFiles_InvalidPaths()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var criteria = conventions.Criteria.ForFramework(NuGetFramework.Parse("net46"));

            var collection = new ContentItemCollection();

            collection.Load(new string[]
            {
                "contentFiles/any/config1.xml",
                "contentFiles/in.valid/net45/config2.xml",
                "contentFiles/any/config3.xml",
                "contentFiles/config4.xml",
                "contentFiles",
                "contentFiles/+/uap10.0.0/config6.xml"
            });

            // Act
            List <ContentItemGroup> contentFileGroups = new();

            collection.PopulateItemGroups(conventions.Patterns.ContentFiles, contentFileGroups);

            // Assert
            Assert.Equal(0, contentFileGroups.Count());
        }
Exemple #5
0
        public void ContentModel_BuildAnyFolderTreatedAsDotNet()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var collection = new ContentItemCollection();

            collection.Load(new string[]
            {
                "build/any/packageA.targets"
            });

            // Act
            List <ContentItemGroup> groups = new();

            collection.PopulateItemGroups(conventions.Patterns.MSBuildFiles, groups);
            var framework = groups
                            .Select(group => ((NuGetFramework)group.Properties["tfm"]))
                            .Single();

            // Assert
            Assert.Equal(".NETPlatform", framework.Framework);
        }
Exemple #6
0
        public void ContentModel_RuntimesAnyMapsToDotnet()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var collection = new ContentItemCollection();

            collection.Load(new string[]
            {
                "runtimes/any/lib/any/a.dll",
            });

            // Act
            List <ContentItemGroup> itemGroups = new();

            collection.PopulateItemGroups(conventions.Patterns.RuntimeAssemblies, itemGroups);
            var groups = itemGroups
                         .OrderBy(group => ((NuGetFramework)group.Properties["tfm"]).GetShortFolderName())
                         .ToList();

            // Assert
            Assert.Equal(1, groups.Count);
            Assert.Equal(FrameworkConstants.CommonFrameworks.DotNet, (NuGetFramework)groups[0].Properties["tfm"]);
        }
Exemple #7
0
        private static List <LockFileRuntimeTarget> GetRuntimeTargetLockFileItems(
            ContentItemCollection contentItems,
            NuGetFramework framework,
            LibraryIncludeFlags dependencyType,
            LibraryIncludeFlags groupType,
            PatternSet patternSet,
            string assetType)
        {
            List <ContentItemGroup> groups = new List <ContentItemGroup>();

            contentItems.PopulateItemGroups(patternSet, groups);

            var groupsForFramework = GetContentGroupsForFramework(
                framework,
                groups,
                ManagedCodeConventions.PropertyNames.RuntimeIdentifier);

            var items = GetRuntimeTargetItems(groupsForFramework, assetType);

            if ((dependencyType & groupType) == LibraryIncludeFlags.None)
            {
                ClearIfExists <LockFileRuntimeTarget>(items);
            }

            return(items);
        }
Exemple #8
0
        public void ContentModel_BuildNoFilesAtRootNoAnyGroup()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var collection = new ContentItemCollection();

            collection.Load(new string[]
            {
                "build/net46/packageA.targets",
                "build/net45/packageA.targets",
                "build/net35/packageA.targets",
                "build/net20/packageA.targets",
                "build/uap10.0/packageA.targets",
            });

            // Act
            List <ContentItemGroup> itemGroups = new();

            collection.PopulateItemGroups(conventions.Patterns.MSBuildFiles, itemGroups);
            var groups = itemGroups
                         .Select(group => ((NuGetFramework)group.Properties["tfm"]))
                         .ToList();

            // Assert
            Assert.Equal(0, groups.Count(framework => framework == NuGetFramework.AnyFramework));
        }
Exemple #9
0
        public void ContentModel_BuildRootFolderRandomFiles()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var collection = new ContentItemCollection();

            collection.Load(new string[]
            {
                "build/config.xml",
                "build/net45/task.dll",
                "build/net45/task.targets",
                "build/net45/task.props",
            });

            // Act
            List <ContentItemGroup> groups = new();

            collection.PopulateItemGroups(conventions.Patterns.MSBuildFiles, groups);

            // Assert
            Assert.Equal(1, groups.Count());
            Assert.Equal(NuGetFramework.Parse("net45"), groups.First().Properties["tfm"] as NuGetFramework);
        }
        public void ContentModel_AnyTFMDefaulsToAny()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var collection = new ContentItemCollection();
            var rid        = "win-x86";

            collection.Load(new string[]
            {
                $"tools/any/{rid}/a.dll",
            });

            // Act
            List <ContentItemGroup> groups = new();

            collection.PopulateItemGroups(conventions.Patterns.ToolsAssemblies, groups);

            // Assert
            Assert.Equal(1, groups.Count);
            Assert.Equal(NuGetFramework.AnyFramework, (NuGetFramework)groups.First().Properties["tfm"]);
            Assert.Equal(rid, groups.First().Properties["rid"]);
        }
Exemple #11
0
        public void ContentFiles_Empty()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var criteria = conventions.Criteria.ForFramework(NuGetFramework.Parse("net46"));

            var collection = new ContentItemCollection();

            collection.Load(new string[]
            {
                // empty
            });

            // Act
            List <ContentItemGroup> contentFileGroups = new();

            collection.PopulateItemGroups(conventions.Patterns.ContentFiles, contentFileGroups);

            // Assert
            Assert.Equal(0, contentFileGroups.Count());
        }
        public void ContentModel_NoTFMAndRuntimeIdentifierNoMatch()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var collection = new ContentItemCollection();

            collection.Load(new string[]
            {
                "tools/a.dll",
            });

            // Act
            List <ContentItemGroup> itemGroups = new();

            collection.PopulateItemGroups(conventions.Patterns.ToolsAssemblies, itemGroups);
            var groups = itemGroups
                         .Select(group => ((NuGetFramework)group.Properties["tfm"]))
                         .ToList();

            // Assert
            Assert.Equal(0, groups.Count);
        }
        private static IEnumerable <NuGetFramework> GetPackageFrameworks(
            CompatibilityData compatibilityData,
            RestoreTargetGraph graph)
        {
            var available = new HashSet <NuGetFramework>();

            var contentItems = new ContentItemCollection();

            contentItems.Load(compatibilityData.Files);

            var patterns = new[]
            {
                graph.Conventions.Patterns.ResourceAssemblies,
                graph.Conventions.Patterns.CompileRefAssemblies,
                graph.Conventions.Patterns.RuntimeAssemblies,
                graph.Conventions.Patterns.EmbedAssemblies,
                graph.Conventions.Patterns.ContentFiles
            };

            List <ContentItemGroup> itemGroups = new();

            foreach (var pattern in patterns)
            {
                itemGroups.Clear();
                contentItems.PopulateItemGroups(pattern, itemGroups);
                foreach (var group in itemGroups)
                {
                    // lib/net45/subfolder/a.dll will be returned as a group with zero items since sub
                    // folders are not allowed. Completely empty groups are not compatible, a group with
                    // _._ would contain _._ as an item.
                    if (group.Items.Count > 0)
                    {
                        group.Properties.TryGetValue(ManagedCodeConventions.PropertyNames.RuntimeIdentifier, out var ridObj);
                        group.Properties.TryGetValue(ManagedCodeConventions.PropertyNames.TargetFrameworkMoniker, out var tfmObj);

                        var tfm = tfmObj as NuGetFramework;

                        // RID specific items should be ignored here since they are only used in the runtime assembly check
                        if (ridObj == null && tfm?.IsSpecificFramework == true)
                        {
                            available.Add(tfm);
                        }
                    }
                }
            }

            return(available);
        }
Exemple #14
0
        public void ContentFiles_BasicContentModelCheck()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var criteria = conventions.Criteria.ForFramework(NuGetFramework.Parse("net46"));

            var collection = new ContentItemCollection();

            collection.Load(new string[]
            {
                "contentFiles/any/net45/config1.xml",
                "contentFiles/cs/net45/config2.xml",
                "contentFiles/vb/net45/config3.xml",
                "contentFiles/any/uap/config4.xml",
                "contentFiles/cs/uap/config5.xml",
                "contentFiles/vb/uap/config6.xml"
            });

            // Act
            List <ContentItemGroup> contentFileGroups = new();

            collection.PopulateItemGroups(conventions.Patterns.ContentFiles, contentFileGroups);

            // Assert
            Assert.Equal(6, contentFileGroups.Count());

            Assert.Equal("any|cs|vb", string.Join("|",
                                                  contentFileGroups.Select(group =>
                                                                           group.Properties[ManagedCodeConventions.PropertyNames.CodeLanguage])
                                                  .Distinct()
                                                  .OrderBy(s => s)));

            Assert.Equal("net45|uap", string.Join("|",
                                                  contentFileGroups.Select(group =>
                                                                           group.Properties[ManagedCodeConventions.PropertyNames.TargetFrameworkMoniker] as NuGetFramework)
                                                  .Select(f => f.GetShortFolderName())
                                                  .Distinct()
                                                  .OrderBy(s => s)));
        }
Exemple #15
0
        public void ContentModel_BuildNoFilesAtRoot()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var collection = new ContentItemCollection();

            collection.Load(new string[]
            {
                "build/net46/packageA.targets",
                "build/net45/packageA.targets",
                "build/net35/packageA.targets",
                "build/net20/packageA.targets",
                "build/uap10.0/packageA.targets",
            });

            // Act
            List <ContentItemGroup> itemGroups = new();

            collection.PopulateItemGroups(conventions.Patterns.MSBuildFiles, itemGroups);
            var groups = itemGroups
                         .OrderBy(group => ((NuGetFramework)group.Properties["tfm"]).GetShortFolderName())
                         .ToList();

            // Assert
            Assert.Equal(5, groups.Count());
            Assert.Equal(NuGetFramework.Parse("net20"), groups[0].Properties["tfm"] as NuGetFramework);
            Assert.Equal(NuGetFramework.Parse("net35"), groups[1].Properties["tfm"] as NuGetFramework);
            Assert.Equal(NuGetFramework.Parse("net45"), groups[2].Properties["tfm"] as NuGetFramework);
            Assert.Equal(NuGetFramework.Parse("net46"), groups[3].Properties["tfm"] as NuGetFramework);
            Assert.Equal(NuGetFramework.Parse("uap10.0"), groups[4].Properties["tfm"] as NuGetFramework);

            Assert.Equal("build/net20/packageA.targets", groups[0].Items.Single().Path);
            Assert.Equal("build/net35/packageA.targets", groups[1].Items.Single().Path);
            Assert.Equal("build/net45/packageA.targets", groups[2].Items.Single().Path);
            Assert.Equal("build/net46/packageA.targets", groups[3].Items.Single().Path);
            Assert.Equal("build/uap10.0/packageA.targets", groups[4].Items.Single().Path);
        }
Exemple #16
0
        private static void AddContentFiles(ManagedCodeConventions managedCodeConventions, LockFileTargetLibrary lockFileLib, NuGetFramework framework, ContentItemCollection contentItems, NuspecReader nuspec)
        {
            // content v2 items
            List <ContentItemGroup> contentFileGroups = new();

            contentItems.PopulateItemGroups(managedCodeConventions.Patterns.ContentFiles, contentFileGroups);

            if (contentFileGroups.Count > 0)
            {
                // Multiple groups can match the same framework, find all of them
                var contentFileGroupsForFramework = ContentFileUtils.GetContentGroupsForFramework(
                    framework,
                    contentFileGroups);

                lockFileLib.ContentFiles = ContentFileUtils.GetContentFileGroup(
                    nuspec,
                    contentFileGroupsForFramework);
            }
        }
Exemple #17
0
        public void ContentFiles_BasicContentModelSubFolders()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var criteria = conventions.Criteria.ForFramework(NuGetFramework.Parse("net46"));

            var collection = new ContentItemCollection();

            collection.Load(new string[]
            {
                "contentFiles/any/net45/config1.xml",
                "contentFiles/any/net45/folder/a/b/c/config2.xml",
            });

            // Act
            List <ContentItemGroup> contentFileGroups = new();

            collection.PopulateItemGroups(conventions.Patterns.ContentFiles, contentFileGroups);

            // Assert
            Assert.Equal(1, contentFileGroups.Count());
            Assert.Equal(2, contentFileGroups.Single().Items.Count);

            Assert.Equal("any", contentFileGroups.Select(group =>
                                                         (string)group.Properties[ManagedCodeConventions.PropertyNames.CodeLanguage])
                         .Single());

            Assert.Equal("contentFiles/any/net45/config1.xml|contentFiles/any/net45/folder/a/b/c/config2.xml",
                         string.Join("|",
                                     contentFileGroups.SelectMany(group => group.Items)
                                     .Select(item => item.Path)
                                     .OrderBy(s => s)));
        }
        public void ContentModel_Net46TFMAndAnyRIDisAnyRID()
        {
            // Arrange
            var conventions = new ManagedCodeConventions(
                new RuntimeGraph(
                    new List <CompatibilityProfile>()
            {
                new CompatibilityProfile("net46.app")
            }));

            var collection = new ContentItemCollection();
            var rid        = "any";

            collection.Load(new string[]
            {
                $"tools/net46/{rid}/a.dll",
            });

            // Arrange
            var criteria = conventions.Criteria.ForFrameworkAndRuntime(NuGetFramework.Parse("net46"), rid);

            // Act
            var group = collection.FindBestItemGroup(criteria, conventions.Patterns.ToolsAssemblies);

            // Assert
            Assert.Equal(FrameworkConstants.CommonFrameworks.Net46, (NuGetFramework)group.Properties["tfm"]);
            Assert.Equal(rid, group.Properties["rid"]);

            // Act
            List <ContentItemGroup> groups = new();

            collection.PopulateItemGroups(conventions.Patterns.ToolsAssemblies, groups);

            // Assert
            Assert.Equal(1, groups.Count);
            Assert.Equal(FrameworkConstants.CommonFrameworks.Net46, (NuGetFramework)groups.First().Properties["tfm"]);
            Assert.Equal(rid, groups.First().Properties["rid"]);
        }
Exemple #19
0
 internal static void GetContentForPattern(ContentItemCollection collection, PatternSet pattern, IList <ContentItemGroup> itemGroups)
 {
     collection.PopulateItemGroups(pattern, itemGroups);
 }