private static bool ValidateDependencies()

in src/Amazon.Lambda.Tools/LambdaPackager.cs [406:485]


        private static bool ValidateDependencies(IToolLogger logger, string targetFramework, JsonData depsJsonTargetNode, bool disableVersionCheck)
        {
            Version maxNETStandardLibraryVersion;
            // If we don't know the NETStandard.Library NuGet package version then skip validation. This is to handle
            // the case we are packaging up for a future target framework verion then this version of the tooling knows about.
            // Skip validation so the tooling doesn't get in the way.
            if (!NETSTANDARD_LIBRARY_VERSIONS.TryGetValue(targetFramework, out maxNETStandardLibraryVersion))
                return true;

            var dependenciesUsingNETStandard = new List<string>();
            Version referencedNETStandardLibrary = null;

            var errorLevel = disableVersionCheck ? "Warning" : "Error";

            foreach (KeyValuePair<string, JsonData> dependencyNode in depsJsonTargetNode)
            {
                var nameAndVersion = dependencyNode.Key.Split('/');
                if (nameAndVersion.Length != 2)
                    continue;

                if (string.Equals(nameAndVersion[0], "netstandard.library", StringComparison.OrdinalIgnoreCase))
                {
                    if(!Version.TryParse(nameAndVersion[1], out referencedNETStandardLibrary))
                    {
                        logger.WriteLine($"{errorLevel} parsing version number for declared NETStandard.Library: {nameAndVersion[1]}");
                        return true;
                    }
                }
                // Collect the dependencies that are pulling in the NETStandard.Library metapackage
                else
                {
                    var subDependencies = dependencyNode.Value["dependencies"];
                    if (subDependencies != null)
                    {
                        foreach (KeyValuePair<string, JsonData> subDependency in subDependencies)
                        {
                            if (string.Equals(subDependency.Key, "netstandard.library", StringComparison.OrdinalIgnoreCase))
                            {
                                dependenciesUsingNETStandard.Add(nameAndVersion[0] + " : " + nameAndVersion[1]);
                                break;
                            }
                        }
                    }
                }
            }

            // If true the project is pulling in a new version of NETStandard.Library then the target framework supports.
            if(referencedNETStandardLibrary != null && maxNETStandardLibraryVersion < referencedNETStandardLibrary)
            {
                logger?.WriteLine($"{errorLevel}: Project is referencing NETStandard.Library version {referencedNETStandardLibrary}. Max version supported by {targetFramework} is {maxNETStandardLibraryVersion}.");

                // See if we can find the target framework that does support the version the project is pulling in.
                // This can help the user know what framework their dependencies are targeting instead of understanding NuGet version numbers.
                var matchingTargetFramework = NETSTANDARD_LIBRARY_VERSIONS.FirstOrDefault(x =>
                {
                    return x.Value.Equals(referencedNETStandardLibrary);
                });

                if(!string.IsNullOrEmpty(matchingTargetFramework.Key))
                {
                    logger?.WriteLine($"{errorLevel}: NETStandard.Library {referencedNETStandardLibrary} is used for target framework {matchingTargetFramework.Key}.");
                }

                if (dependenciesUsingNETStandard.Count != 0)
                {
                    logger?.WriteLine($"{errorLevel}: Check the following dependencies for versions compatible with {targetFramework}:");
                    foreach(var dependency in dependenciesUsingNETStandard)
                    {
                        logger?.WriteLine($"{errorLevel}: \t{dependency}");
                    }
                }

                // If disable version check is true still write the warning messages 
                // but return true to continue deployment.
                return disableVersionCheck;
            }


            return true;
        }