private void ParseManagedSemantics() { var stringTable = m_context.PathTable.StringTable; var magicNugetMarker = PathAtom.Create(stringTable, "_._"); var dllExtension = PathAtom.Create(stringTable, ".dll"); foreach (var relativePath in PackageOnDisk.Contents.OrderBy(path => path.ToString(stringTable))) { // This is a dll. Check if it is in a lib folder or ref folder. // This code handles two layouts // Case 1: /runtimes/{targetRuntime}/[lib|ref]/{targetFramework}/{fileName} // Case 2: /[lib|ref]/{targetFramework}/{fileName} // In case 1, /runtimes/{targetRuntime} is removed and then rest of string is processed as in // case 2. // Case 2 treats files under 'lib' folder as runtime dependencies (and optionally compile-time // references if missing a corresponding set of compile-time references for the target framework // under the 'ref' folder). Files under 'ref' folder are treated strictly as compile-time only references. var atoms = new ReadOnlySpan <PathAtom>(relativePath.GetAtoms()); if (atoms.Length == 5) { var isRuntime = NugetFrameworkMonikers.RuntimesFolderName.CaseInsensitiveEquals(stringTable, atoms[0]) && NugetFrameworkMonikers.SupportedTargetRuntimeAtoms.Contains(atoms[1].StringId); if (isRuntime) { atoms = atoms.Slice(2); } } if (atoms.Length == 3) { var libOrRef = atoms[0]; var targetFrameworkFolder = atoms[1]; var fileName = atoms[2]; var isLib = NugetFrameworkMonikers.LibFolderName.CaseInsensitiveEquals(stringTable, libOrRef); var isRef = NugetFrameworkMonikers.RefFolderName.CaseInsensitiveEquals(stringTable, libOrRef); if (isLib || isRef) { if (!TryGetKnownTargetFramework(targetFrameworkFolder, out NugetTargetFramework targetFramework)) { // We skip unknown frameworks, packages are not necessarily well constructed. We log this // as a verbose message (i.e., this is not an error). Logger.Log.NugetUnknownFramework(m_context.LoggingContext, PackageOnDisk.Package.Id, targetFrameworkFolder.ToString(stringTable), relativePath.ToString(stringTable)); continue; } var isManagedEntry = false; var ext = fileName.GetExtension(stringTable); if (dllExtension.CaseInsensitiveEquals(stringTable, ext)) { isManagedEntry = true; if (isRef) { References.Add(targetFramework, relativePath); } if (isLib) { Libraries.Add(targetFramework, relativePath); } } else if (fileName == magicNugetMarker) { isManagedEntry = true; } if (isManagedEntry) { IsManagedPackage = true; if (!TargetFrameworks.Contains(targetFramework.Moniker)) { TargetFrameworks.Add(targetFramework.Moniker); } // The magic marker is there so the framework is declared as supported, but no actual files are listed // So we don't want to add a magic marker as a real artifact that can be referenced. if (fileName != magicNugetMarker) { AssemblyToTargetFramework.Add(fileName, targetFramework); } } } } } if (TargetFrameworks.Count == 0) { var history = ForceFullFrameworkQualifiersOnly ? NugetFrameworkMonikers.FullFrameworkVersionHistory : NugetFrameworkMonikers.WellknownMonikers.ToList(); foreach (var moniker in history) { TargetFrameworks.Add(moniker); } } // For the refs without lib, copy them to refs. foreach (var kv in Libraries) { if (!References.ContainsKey(kv.Key)) { References.Add(kv.Key, kv.Value.ToArray()); } } }
private void ParseManagedSemantics() { var stringTable = m_context.PathTable.StringTable; var magicNugetMarker = PathAtom.Create(stringTable, "_._"); var dllExtension = PathAtom.Create(stringTable, ".dll"); foreach (var relativePath in PackageOnDisk.Contents.OrderBy(path => path.ToString(stringTable))) { // This is a dll. Check if it is in a lib folder or ref folder. var atoms = relativePath.GetAtoms(); if (atoms.Length == 3) { var libOrRef = atoms[0]; var targetFrameworkFolder = atoms[1]; var fileName = atoms[2]; var isLib = NugetFrameworkMonikers.LibFolderName.CaseInsensitiveEquals(stringTable, libOrRef); var isRef = NugetFrameworkMonikers.RefFolderName.CaseInsensitiveEquals(stringTable, libOrRef); if (isLib || isRef) { if (!TryGetKnownTargetFramework(targetFrameworkFolder, out NugetTargetFramework targetFramework)) { // We skip unknown frameworks, packages are not necessarily well constructed. We log this // as a verbose message (i.e., this is not an error). Logger.Log.NugetUnknownFramework(m_context.LoggingContext, PackageOnDisk.Package.Id, targetFrameworkFolder.ToString(stringTable), relativePath.ToString(stringTable)); continue; } var isManagedEntry = false; var ext = fileName.GetExtension(stringTable); if (dllExtension.CaseInsensitiveEquals(stringTable, ext)) { isManagedEntry = true; if (isRef) { References.Add(targetFramework, relativePath); } if (isLib) { Libraries.Add(targetFramework, relativePath); } } else if (fileName == magicNugetMarker) { isManagedEntry = true; } if (isManagedEntry) { IsManagedPackage = true; if (!TargetFrameworks.Contains(targetFramework.Moniker)) { TargetFrameworks.Add(targetFramework.Moniker); } // The magic marker is there so the framework is declared as supported, but no actual files are listed // So we don't want to add a magic marker as a real artifact that can be referenced. if (fileName != magicNugetMarker) { AssemblyToTargetFramework.Add(fileName, targetFramework); } } } } } if (TargetFrameworks.Count == 0) { var history = ForceFullFrameworkQualifiersOnly ? NugetFrameworkMonikers.FullFrameworkVersionHistory : NugetFrameworkMonikers.WellknownMonikers.ToList(); foreach (var moniker in history) { TargetFrameworks.Add(moniker); } } // For the refs without lib, copy them to refs. foreach (var kv in Libraries) { if (!References.ContainsKey(kv.Key)) { References.Add(kv.Key, kv.Value.ToArray()); } } }