public void ContentModel_BuildRootFolderAndTFM() { // Arrange var conventions = new ManagedCodeConventions( new RuntimeGraph( new List <CompatibilityProfile>() { new CompatibilityProfile("net46.app") })); var criteria = conventions.Criteria.ForFramework(NuGetFramework.AnyFramework); var collection = new ContentItemCollection(); collection.Load(new string[] { "build/packageA.targets", "build/packageA.props", "build/config.xml", "build/net45/task.dll", "build/net45/task.targets", "build/net45/task.props", }); // Act var group = collection.FindBestItemGroup(criteria, conventions.Patterns.MSBuildFiles); var items = group.Items.OrderBy(item => item.Path).ToList(); // Assert Assert.Equal(2, items.Count); Assert.Equal("build/packageA.props", items[0].Path); Assert.Equal("build/packageA.targets", items[1].Path); }
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 var groups = collection.FindItemGroups(conventions.Patterns.MSBuildFiles) .Select(group => ((NuGetFramework)group.Properties["tfm"])) .ToList(); // Assert Assert.Equal(0, groups.Count(framework => framework == NuGetFramework.AnyFramework)); }
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 var framework = collection.FindItemGroups(conventions.Patterns.MSBuildFiles) .Select(group => ((NuGetFramework)group.Properties["tfm"])) .Single(); // Assert Assert.Equal(".NETPlatform", framework.Framework); }
private RestoreTargetGraph(IEnumerable <ResolverConflict> conflicts, bool writeToLockFile, NuGetFramework framework, string runtimeIdentifier, RuntimeGraph runtimeGraph, IEnumerable <GraphNode <RemoteResolveResult> > graphs, ISet <RemoteMatch> install, ISet <GraphItem <RemoteResolveResult> > flattened, ISet <LibraryRange> unresolved, AnalyzeResult <RemoteResolveResult> analyzeResult) { Conflicts = conflicts; WriteToLockFile = writeToLockFile; RuntimeIdentifier = runtimeIdentifier; RuntimeGraph = runtimeGraph; Framework = framework; Graphs = graphs; Name = FrameworkRuntimePair.GetName(Framework, RuntimeIdentifier); Conventions = new ManagedCodeConventions(runtimeGraph); Install = install; Flattened = flattened; AnalyzeResult = analyzeResult; Unresolved = unresolved; }
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 var groups = collection.FindItemGroups(conventions.Patterns.MSBuildFiles); // Assert Assert.Equal(1, groups.Count()); Assert.Equal(NuGetFramework.Parse("net45"), groups.First().Properties["tfm"] as NuGetFramework); }
public void ContentModel_RuntimeAgnosticFallbackReverse() { // Arrange var conventions = new ManagedCodeConventions( new RuntimeGraph( new List <CompatibilityProfile>() { new CompatibilityProfile("netcore50.app") })); var collection = new ContentItemCollection(); collection.Load(new string[] { "lib/netcore50/System.Reflection.Emit.dll", "runtimes/aot/lib/netcore50/System.Reflection.Emit.dll", }); var criteria = conventions.Criteria.ForFramework(NuGetFramework.Parse("netcore50")); // Act var group = collection.FindBestItemGroup(criteria, conventions.Patterns.RuntimeAssemblies); // Assert Assert.Equal("lib/netcore50/System.Reflection.Emit.dll", group.Items.Single().Path); }
public void ContentModel_LibNoFilesAtRootNoAnyGroup() { // 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/uap10.0/a.dll", }); List <ContentItemGroup> itemGroups = new(); collection.PopulateItemGroups(conventions.Patterns.RuntimeAssemblies, itemGroups); var groups = itemGroups .Select(group => ((NuGetFramework)group.Properties["tfm"])) .ToList(); // Assert Assert.Equal(0, groups.Count(framework => framework == NuGetFramework.AnyFramework)); }
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"]); }
public void ContentModel_LibNet46WithSubFoldersAreIgnored() { // 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[] { "lib/net46/a.dll", "lib/net46/sub/a.dll", }); // Act var group = collection.FindBestItemGroup(criteria, conventions.Patterns.RuntimeAssemblies); // Assert Assert.Equal(1, group.Items.Count); Assert.Equal("lib/net46/a.dll", group.Items[0].Path); }
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"]); }
public void ContentModel_ResourcesAnyMapsToDotnet() { // Arrange var conventions = new ManagedCodeConventions( new RuntimeGraph( new List <CompatibilityProfile>() { new CompatibilityProfile("net46.app") })); var collection = new ContentItemCollection(); collection.Load(new string[] { "lib/any/en-us/a.resources.dll", }); // Act var groups = collection.FindItemGroups(conventions.Patterns.ResourceAssemblies) .OrderBy(group => ((NuGetFramework)group.Properties["tfm"]).GetShortFolderName()) .ToList(); // Assert Assert.Equal(1, groups.Count); Assert.Equal(FrameworkConstants.CommonFrameworks.DotNet, (NuGetFramework)groups[0].Properties["tfm"]); }
public void ContentModel_ToolsAnyMapsToAny() { // Arrange var conventions = new ManagedCodeConventions( new RuntimeGraph( new List <CompatibilityProfile>() { new CompatibilityProfile("net46.app") })); var collection = new ContentItemCollection(); collection.Load(new string[] { "tools/any/bla/a.dll", }); // Act var groups = collection.FindItemGroups(conventions.Patterns.ToolsAssemblies) .OrderBy(group => ((NuGetFramework)group.Properties["tfm"]).GetShortFolderName()) .ToList(); // Assert Assert.Equal(1, groups.Count); Assert.Equal(NuGetFramework.AnyFramework, (NuGetFramework)groups[0].Properties["tfm"]); }
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 var contentFileGroups = collection.FindItemGroups(conventions.Patterns.ContentFiles); // Assert Assert.Equal(0, contentFileGroups.Count()); }
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 var contentFileGroups = collection.FindItemGroups(conventions.Patterns.ContentFiles); // Assert Assert.Equal(0, contentFileGroups.Count()); }
public void ContentModel_MSBuildAnyMapsToDotnet() { // Arrange var conventions = new ManagedCodeConventions( new RuntimeGraph( new List <CompatibilityProfile>() { new CompatibilityProfile("net46.app") })); var collection = new ContentItemCollection(); collection.Load(new string[] { "build/any/a.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(1, groups.Count); Assert.Equal(FrameworkConstants.CommonFrameworks.DotNet, (NuGetFramework)groups[0].Properties["tfm"]); }
private RestoreTargetGraph(IEnumerable <ResolverConflict> conflicts, NuGetFramework framework, string runtimeIdentifier, RuntimeGraph runtimeGraph, IEnumerable <GraphNode <RemoteResolveResult> > graphs, ISet <RemoteMatch> install, ISet <GraphItem <RemoteResolveResult> > flattened, ISet <LibraryRange> unresolved, AnalyzeResult <RemoteResolveResult> analyzeResult, ISet <ResolvedDependencyKey> resolvedDependencies) { Conflicts = conflicts.ToArray(); RuntimeIdentifier = runtimeIdentifier; RuntimeGraph = runtimeGraph; Framework = framework; Graphs = graphs; Name = FrameworkRuntimePair.GetName(Framework, RuntimeIdentifier); TargetGraphName = FrameworkRuntimePair.GetTargetGraphName(Framework, RuntimeIdentifier); Conventions = new ManagedCodeConventions(runtimeGraph); Install = install; Flattened = flattened; AnalyzeResult = analyzeResult; Unresolved = unresolved; ResolvedDependencies = resolvedDependencies; }
public void ContentModel_NativeSubFoldersAllowed() { // Arrange var runtimeGraph = new RuntimeGraph( new List <RuntimeDescription>() { new RuntimeDescription("any"), new RuntimeDescription("win7", new[] { "any" }), new RuntimeDescription("win7-x64", new[] { "any", "win7" }), new RuntimeDescription("win7-x86", new[] { "any", "win7" }) }, new List <CompatibilityProfile>() { new CompatibilityProfile("netcore50.app") }); var conventions = new ManagedCodeConventions(runtimeGraph); var collection = new ContentItemCollection(); collection.Load(new string[] { "runtimes/win7-x64/native/sub/a.dll" }); var criteria1 = conventions.Criteria.ForRuntime("win7-x64"); // Act var group1 = collection.FindBestItemGroup(criteria1, conventions.Patterns.NativeLibraries); var result1 = string.Join("|", group1.Items.Select(item => item.Path).OrderBy(s => s)); // Assert Assert.Equal("runtimes/win7-x64/native/sub/a.dll", result1); }
public void ContentModel_NoRidMatchReturnsNothing() { // Arrange var runtimeGraph = new RuntimeGraph( new List <RuntimeDescription>() { new RuntimeDescription("any"), new RuntimeDescription("win7", new[] { "any" }), new RuntimeDescription("win7-x64", new[] { "any", "win7" }), new RuntimeDescription("win7-x86", new[] { "any", "win7" }) }, new List <CompatibilityProfile>() { new CompatibilityProfile("netcore50.app") }); var conventions = new ManagedCodeConventions(runtimeGraph); var collection = new ContentItemCollection(); collection.Load(new string[] { "runtimes/win7/nativeassets/win81/a.dll", "runtimes/win7/nativeassets/win8/a.dll", "runtimes/win7/native/a.dll", }); var criteria = conventions.Criteria.ForFrameworkAndRuntime(NuGetFramework.Parse("win8"), "linux"); // Act var group = collection.FindBestItemGroup(criteria, conventions.Patterns.NativeLibraries); // Assert Assert.Null(group); }
public void ContentModel_AnyTFMDefaultsToAnyandAnyRIDisAnyRID() { // 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/any/{rid}/a.dll", }); // Act var groups = collection.FindItemGroups(conventions.Patterns.ToolsAssemblies) .ToList(); // Assert Assert.Equal(1, groups.Count); Assert.Equal(NuGetFramework.AnyFramework, (NuGetFramework)groups.First().Properties["tfm"]); Assert.Equal(rid, groups.First().Properties["rid"]); }
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 var groups = collection.FindItemGroups(conventions.Patterns.ToolsAssemblies) .Select(group => ((NuGetFramework)group.Properties["tfm"])) .ToList(); // Assert Assert.Equal(0, groups.Count); }
public void ContentFiles_NetStandardFallbackToAny() { // Arrange var conventions = new ManagedCodeConventions( new RuntimeGraph( new List <CompatibilityProfile>() { new CompatibilityProfile("netstandard13.app") })); var criteria = conventions.Criteria.ForFramework(NuGetFramework.Parse("netstandard1.3")); var collection = new ContentItemCollection(); collection.Load(new string[] { "contentFiles/any/any/config1.xml", "contentFiles/any/dotnet/config1.xml", "contentFiles/any/netstandard1.4/config1.xml" }); // Act var contentFileGroup = collection.FindBestItemGroup(criteria, conventions.Patterns.ContentFiles); var file = contentFileGroup.Items.Single().Path; // Assert Assert.Equal("contentFiles/any/any/config1.xml", file); }
private static void ValidateFileFrameworks(IEnumerable <IPackageFile> files) { var set = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var file in files.Where(t => t.Path != null).Select(t => PathUtility.GetPathWithDirectorySeparator(t.Path))) { set.Add(file); } var managedCodeConventions = new ManagedCodeConventions(new RuntimeGraph()); var collection = new ContentItemCollection(); collection.Load(set.Select(path => path.Replace('\\', '/')).ToArray()); var patterns = managedCodeConventions.Patterns; var frameworkPatterns = new List <PatternSet>() { patterns.RuntimeAssemblies, patterns.CompileRefAssemblies, patterns.CompileLibAssemblies, patterns.NativeLibraries, patterns.ResourceAssemblies, patterns.MSBuildFiles, patterns.ContentFiles, patterns.ToolsAssemblies, patterns.EmbedAssemblies, patterns.MSBuildTransitiveFiles }; var warnPaths = new HashSet <string>(); var frameworksMissingPlatformVersion = new HashSet <string>(); foreach (var pattern in frameworkPatterns) { IEnumerable <ContentItemGroup> targetedItemGroups = ContentExtractor.GetContentForPattern(collection, pattern); foreach (ContentItemGroup group in targetedItemGroups) { foreach (ContentItem item in group.Items) { var framework = (NuGetFramework)item.Properties["tfm"]; if (framework == null) { continue; } if (framework.HasPlatform && framework.PlatformVersion == FrameworkConstants.EmptyVersion) { frameworksMissingPlatformVersion.Add(framework.GetShortFolderName()); } } } } if (frameworksMissingPlatformVersion.Any()) { throw new PackagingException(NuGetLogCode.NU1012, string.Format(CultureInfo.CurrentCulture, Strings.MissingTargetPlatformVersionsFromIncludedFiles, string.Join(", ", frameworksMissingPlatformVersion.OrderBy(str => str)))); } }
private IEnumerable <string> GetAssembliesForFramework(LocalPackageInfo package, NuGetFramework framework, IEnumerable <string> files) { var contentItems = new NuGet.ContentModel.ContentItemCollection(); HashSet <string> referenceFilter = null; contentItems.Load(files); // This will throw an appropriate error if the nuspec is missing var nuspec = package.Nuspec; IList <string> compileTimeAssemblies = null; IList <string> runtimeAssemblies = null; var referenceSet = nuspec.GetReferenceGroups().GetNearest(framework); if (referenceSet != null) { referenceFilter = new HashSet <string>(referenceSet.Items, StringComparer.OrdinalIgnoreCase); } var conventions = new ManagedCodeConventions(null); var managedCriteria = conventions.Criteria.ForFramework(framework); var compileGroup = contentItems.FindBestItemGroup(managedCriteria, conventions.Patterns.CompileAssemblies, conventions.Patterns.RuntimeAssemblies); if (compileGroup != null) { compileTimeAssemblies = compileGroup.Items.Select(t => t.Path).ToList(); } var runtimeGroup = contentItems.FindBestItemGroup(managedCriteria, conventions.Patterns.RuntimeAssemblies); if (runtimeGroup != null) { runtimeAssemblies = runtimeGroup.Items.Select(p => p.Path).ToList(); } // COMPAT: Support lib/contract so older packages can be consumed var contractPath = "lib/contract/" + package.Id + ".dll"; var hasContract = files.Any(path => path == contractPath); var hasLib = runtimeAssemblies?.Any(); if (hasContract && hasLib.HasValue && hasLib.Value && !framework.IsDesktop()) { compileTimeAssemblies.Clear(); compileTimeAssemblies.Add(contractPath); } // Apply filters from the <references> node in the nuspec if (referenceFilter != null) { // Remove anything that starts with "lib/" and is NOT specified in the reference filter. // runtimes/* is unaffected (it doesn't start with lib/) compileTimeAssemblies = compileTimeAssemblies.Where(p => !p.StartsWith("lib/") || referenceFilter.Contains(Path.GetFileName(p))).ToList(); } return(compileTimeAssemblies ?? Enumerable.Empty <string>()); }
/// <summary> /// Extracts the lib files to execution directory /// </summary> /// <param name="package"> /// The package to extract /// </param> /// <param name="runtime"> /// The current runtime /// </param> /// <param name="frameworkName"> /// The current framework name /// </param> /// <param name="executionDir"> /// The execution directory to load packages /// </param> /// <param name="logAction">The log writing action</param> /// <returns> /// The list of extracted files /// </returns> private static IEnumerable <string> ExtractPackage( DownloadResourceResult package, string runtime, NuGetFramework frameworkName, string executionDir, Action <string> logAction = null) { try { var id = package.PackageReader.GetIdentity(); var files = NuGetFrameworkUtility.GetNearest(package.PackageReader.GetLibItems(), frameworkName)?.Items.ToList() ?? NuGetFrameworkUtility.GetNearest(package.PackageReader.GetToolItems(), frameworkName)?.Items.ToList(); if (files == null || files.Count == 0) { var collection = new ContentItemCollection(); collection.Load(package.PackageReader.GetFiles()); var conventions = new ManagedCodeConventions(runtimeGraph); var criteria = conventions.Criteria.ForFrameworkAndRuntime( NuGetFramework.ParseFrameworkName( PackageRepositoryExtensions.CurrentRuntime, DefaultFrameworkNameProvider.Instance), runtime); files = collection.FindBestItemGroup(criteria, conventions.Patterns.NativeLibraries)?.Items .Select(i => i.Path).ToList(); if (files == null || files.Count == 0) { files = collection.FindBestItemGroup(criteria, conventions.Patterns.RuntimeAssemblies)?.Items .Select(i => i.Path).ToList(); } if (files == null || files.Count == 0) { return(new string[0]); } else { logAction?.Invoke($"{id.Id}: {string.Join(", ", files)}"); } } foreach (var file in files) { using (var fileStream = File.Create(Path.Combine(executionDir, Path.GetFileName(file) ?? file))) { package.PackageReader.GetStream(file).CopyTo(fileStream); } } return(files.Select(file => Path.GetFileName(file) ?? file)); } finally { package.Dispose(); } }
public AggregateNuGetAssetResolver(string runtimeFile) { RuntimeGraph runtimeGraph = null; if (!String.IsNullOrEmpty(runtimeFile)) { runtimeGraph = JsonRuntimeFormat.ReadRuntimeGraph(runtimeFile); } _conventions = new ManagedCodeConventions(runtimeGraph); _packages = new Dictionary <string, ContentItemCollection>(); }
public NuGetAssetResolver(string runtimeFile, IEnumerable <string> packageItems) { RuntimeGraph runtimeGraph = null; if (!String.IsNullOrEmpty(runtimeFile)) { runtimeGraph = JsonRuntimeFormat.ReadRuntimeGraph(runtimeFile); } _conventions = new ManagedCodeConventions(runtimeGraph); _sourceItems = new ContentItemCollection(); _sourceItems.Load(packageItems); }
private static void AddToolsAssets( ManagedCodeConventions managedCodeConventions, LockFileTargetLibrary lockFileLib, ContentItemCollection contentItems, IReadOnlyList <SelectionCriteria> orderedCriteria) { var toolsGroup = GetLockFileItems( orderedCriteria, contentItems, managedCodeConventions.Patterns.ToolsAssemblies); lockFileLib.ToolsAssemblies.AddRange(toolsGroup); }
private RestoreTargetGraph(bool inConflict, NuGetFramework framework, string runtimeIdentifier, RuntimeGraph runtimeGraph, GraphNode <RemoteResolveResult> graph, ISet <RemoteMatch> install, ISet <GraphItem <RemoteResolveResult> > flattened, ISet <LibraryRange> unresolved) { InConflict = inConflict; RuntimeIdentifier = runtimeIdentifier; RuntimeGraph = runtimeGraph; Framework = framework; Graph = graph; Conventions = new ManagedCodeConventions(runtimeGraph); Install = install; Flattened = flattened; Unresolved = unresolved; }
internal (HashSet <NuGetFramework>, HashSet <NuGetFramework>, HashSet <NuGetFramework>) Categorize(IEnumerable <string> files, IEnumerable <NuGetFramework> tfmsFromNuspec) { var managedCodeConventions = new ManagedCodeConventions(new RuntimeGraph()); Func <object, object, bool> isCompatible = managedCodeConventions.Properties["tfm"].CompatibilityTest; var collection = new ContentItemCollection(); collection.Load(files); List <ContentItemGroup> libItems = new(); List <ContentItemGroup> refItems = new(); ContentExtractor.GetContentForPattern(collection, managedCodeConventions.Patterns.CompileLibAssemblies, libItems); ContentExtractor.GetContentForPattern(collection, managedCodeConventions.Patterns.CompileRefAssemblies, refItems); var tfmsFromFilesSet = new HashSet <NuGetFramework>(); tfmsFromFilesSet.AddRange(ContentExtractor.GetGroupFrameworks(libItems)); tfmsFromFilesSet.AddRange(ContentExtractor.GetGroupFrameworks(refItems)); var tfmsFromFiles = tfmsFromFilesSet.Where(t => t != Net00).ToList(); var noExactMatchesFromFile = new HashSet <NuGetFramework>(); var noExactMatchesFromNuspec = new HashSet <NuGetFramework>(); var compatNotExactMatches = new HashSet <NuGetFramework>(); noExactMatchesFromFile.AddRange(tfmsFromFiles.Where(t => !tfmsFromNuspec.Contains(t))); noExactMatchesFromNuspec.AddRange(tfmsFromNuspec.Where(t => !tfmsFromFiles.Contains(t))); foreach (var fileTFM in noExactMatchesFromFile) { foreach (var nuspecTFM in noExactMatchesFromNuspec) { if (isCompatible(fileTFM, nuspecTFM)) { compatNotExactMatches.Add(fileTFM); break; } } } if (compatNotExactMatches.Count != 0) { noExactMatchesFromFile.RemoveWhere(p => compatNotExactMatches.Contains(p)); } return(compatNotExactMatches, noExactMatchesFromFile, noExactMatchesFromNuspec); }
internal IEnumerable <PackagingLogMessage> Validate(IEnumerable <string> files) { var managedCodeConventions = new ManagedCodeConventions(new RuntimeGraph()); var collection = new ContentItemCollection(); collection.Load(files); List <ContentItemGroup> libItems = new(); List <ContentItemGroup> refItems = new(); List <ContentItemGroup> buildItems = new(); ContentExtractor.GetContentForPattern(collection, managedCodeConventions.Patterns.CompileLibAssemblies, libItems); ContentExtractor.GetContentForPattern(collection, managedCodeConventions.Patterns.CompileRefAssemblies, refItems); ContentExtractor.GetContentForPattern(collection, managedCodeConventions.Patterns.MSBuildFiles, buildItems); var libFrameworks = ContentExtractor.GetGroupFrameworks(libItems).ToArray(); var refFrameworks = ContentExtractor.GetGroupFrameworks(refItems).ToArray(); var buildFrameworks = ContentExtractor.GetGroupFrameworks(buildItems).ToArray(); if (libFrameworks.Length == 0 && refFrameworks.Length == 0) { //if you can't find the ref and lib folder, then find the build folder if (buildFrameworks.Length != 0) { //if you can find any folders other than native or any, raise an NU5127 if (buildFrameworks.Any(t => (FrameworkConstants.DotNetAll.Satisfies(t) || FrameworkNameValidatorUtility.IsValidFrameworkName(t)) && t.GetShortFolderName() != FrameworkConstants.FrameworkIdentifiers.DotNet && t.GetShortFolderName() != FrameworkConstants.FrameworkIdentifiers.Native)) { var possibleFrameworks = buildFrameworks. Where(t => t.IsSpecificFramework && t.GetShortFolderName() != FrameworkConstants.FrameworkIdentifiers.DotNet && t.GetShortFolderName() != FrameworkConstants.FrameworkIdentifiers.Native). Select(t => t.GetShortFolderName()).ToArray(); (var tfmNames, var suggestedDirectories) = GenerateWarningString(possibleFrameworks); var issue = new List <PackagingLogMessage>(); issue.Add(PackagingLogMessage.CreateWarning(string.Format(MessageFormat, tfmNames, suggestedDirectories), NuGetLogCode.NU5127)); return(issue); } } } return(Array.Empty <PackagingLogMessage>()); }