コード例 #1
0
        private void UpdateForMissingQualifierConversionFunction(Moniker moniker)
        {
            // Check if a compatible one is good for the TargetFrameworks
            foreach (var compatibleMoniker in NugetFrameworkMonikers.CompatibilityMatrix[moniker])
            {
                if (TargetFrameworkWithFallbacks.ContainsKey(compatibleMoniker) && !TargetFrameworkWithFallbacks.ContainsKey(moniker))
                {
                    // Add the framework as compatible with this package for now.
                    TargetFrameworkWithFallbacks.Add(compatibleMoniker, moniker);

                    break;
                }
            }
        }
コード例 #2
0
        /// <nodoc />
        private bool TryParseDependenciesFromNuSpec()
        {
            var dependencyNodes = m_nuSpec
                                  .Elements()
                                  .Where(el => string.Equals(el.Name.LocalName, "package", StringComparison.Ordinal))
                                  .Elements()
                                  .Where(el => string.Equals(el.Name.LocalName, "metadata", StringComparison.Ordinal))
                                  .Elements()
                                  .Where(el => string.Equals(el.Name.LocalName, "dependencies", StringComparison.Ordinal))
                                  .Elements();

            // Namespace independent query, nuget has about 6 different namespaces as of may 2016.
            var  dependencies          = new List <INugetPackage>();
            var  skipIdLookupTable     = new HashSet <string>(this.DependentPackageIdsToSkip);
            var  ignoreIdLookupTable   = new HashSet <string>(this.DependentPackageIdsToIgnore);
            bool skipAllDependencies   = skipIdLookupTable.Contains("*");
            bool ignoreAllDependencies = ignoreIdLookupTable.Contains("*");

            foreach (var dependency in dependencyNodes.Where(el => string.Equals(el.Name.LocalName, "dependency", StringComparison.Ordinal)))
            {
                var genericDependency = ReadDependencyElement(dependency);
                if (genericDependency == null && !(ignoreAllDependencies || ignoreIdLookupTable.Contains(dependency.Attribute("id")?.Value?.Trim())))
                {
                    return(false);
                }

                if (genericDependency != null && !skipAllDependencies && !skipIdLookupTable.Contains(genericDependency.GetPackageIdentity()))
                {
                    dependencies.Add(genericDependency);
                }
            }

            var dependenciesPerFramework = new MultiValueDictionary <PathAtom, INugetPackage>();
            var groups = dependencyNodes.Where(el => string.Equals(el.Name.LocalName, "group", StringComparison.Ordinal));

            foreach (var group in groups)
            {
                if (group.Attribute("targetFramework") != null && NugetFrameworkMonikers.TargetFrameworkNameToMoniker.TryGetValue(group.Attribute("targetFramework").Value, out Moniker targetFramework))
                {
                    // If there is at least one valid dependency for a known framework, then the package is defined as managed
                    IsManagedPackage = group.Elements().Any();
                    TargetFrameworkWithFallbacks.Add(targetFramework);

                    // TODO:Nuget: Clean this up once we got end to end TFM support inside our Nuget toolchain, this is needed to not break backwards compatibility
                    if (string.IsNullOrEmpty(this.Tfm) &&
                        (targetFramework.Equals(NugetFrameworkMonikers.NetCore) ||
                         targetFramework.Equals(NugetFrameworkMonikers.NetStandard10) ||
                         targetFramework.Equals(NugetFrameworkMonikers.NetStandard11) ||
                         targetFramework.Equals(NugetFrameworkMonikers.NetStandard12) ||
                         targetFramework.Equals(NugetFrameworkMonikers.NetStandard13) ||
                         targetFramework.Equals(NugetFrameworkMonikers.NetStandard14) ||
                         targetFramework.Equals(NugetFrameworkMonikers.NetStandard15) ||
                         targetFramework.Equals(NugetFrameworkMonikers.NetStandard16)))
                    {
                        continue;
                    }

                    // If the package has a pinned tfm and the groups tfm does not match, skip the groups dependency resolution
                    if (!string.IsNullOrEmpty(this.Tfm) && NugetFrameworkMonikers.TargetFrameworkNameToMoniker.TryGetValue(this.Tfm, out Moniker pinnedTfm) && !PathAtom.Equals(pinnedTfm, targetFramework))
                    {
                        continue;
                    }

                    foreach (
                        var dependency in
                        group.Elements().Where(
                            el => string.Equals(el.Name.LocalName, "dependency", StringComparison.Ordinal)))
                    {
                        var grouppedDependency = ReadDependencyElement(dependency);
                        if (grouppedDependency == null && !(ignoreAllDependencies || ignoreIdLookupTable.Contains(dependency.Attribute("id")?.Value?.Trim())))
                        {
                            return(false);
                        }

                        if (grouppedDependency != null && !skipAllDependencies && !skipIdLookupTable.Contains(grouppedDependency.GetPackageIdentity()))
                        {
                            dependenciesPerFramework.Add(targetFramework, grouppedDependency);
                        }
                    }
                }
            }

            Dependencies             = dependencies;
            DependenciesPerFramework = dependenciesPerFramework;

            return(true);
        }
コード例 #3
0
        private void ParseManagedSemantics()
        {
            var stringTable      = m_context.PathTable.StringTable;
            var magicNugetMarker = PathAtom.Create(stringTable, "_._");
            var dllExtension     = PathAtom.Create(stringTable, ".dll");

            var refs = new MultiValueDictionary <NugetTargetFramework, RelativePath>();
            var libs = new MultiValueDictionary <NugetTargetFramework, RelativePath>();
            var assemblyToTargetFramework = new MultiValueDictionary <PathAtom, NugetTargetFramework>();

            foreach (var relativePath in PackageOnDisk.Contents)
            {
                // 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)
                            {
                                refs.Add(targetFramework, relativePath);
                            }

                            if (isLib)
                            {
                                libs.Add(targetFramework, relativePath);
                            }
                        }
                        else if (fileName == magicNugetMarker)
                        {
                            isManagedEntry = true;
                        }

                        if (isManagedEntry)
                        {
                            IsManagedPackage = true;

                            if (!TargetFrameworkWithFallbacks.ContainsKey(targetFramework.Moniker))
                            {
                                bool comaptibleMonikerAlreadyPresent = false;
                                if (NugetFrameworkMonikers.CompatibilityMatrix.ContainsKey(targetFramework.Moniker))
                                {
                                    foreach (var compatibleMoniker in NugetFrameworkMonikers.CompatibilityMatrix[targetFramework.Moniker])
                                    {
                                        if (TargetFrameworkWithFallbacks.ContainsKey(compatibleMoniker))
                                        {
                                            comaptibleMonikerAlreadyPresent = true;
                                            break;
                                        }
                                    }
                                }

                                if (!comaptibleMonikerAlreadyPresent)
                                {
                                    // If nuspec does not specify target frameworks, we need to infer from the layout
                                    TargetFrameworkWithFallbacks.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);
                            }
                        }
                    }
                }
            }

            // For the refs without lib, copy them to refs.
            foreach (var kv in libs)
            {
                if (!refs.ContainsKey(kv.Key))
                {
                    refs.Add(kv.Key, kv.Value.ToArray());
                }
            }

            References = refs;
            Libraries  = libs;
            AssemblyToTargetFramework = assemblyToTargetFramework;
        }