private static string NugetSearchFullPathToExecutableAtRoot(string executableName, string executableRoot)
        {
            if (string.IsNullOrWhiteSpace(executableName))
            {
                throw NullOrWhiteSpaceException(nameof(executableName));
            }

            if (string.IsNullOrWhiteSpace(executableRoot))
            {
                throw NullOrWhiteSpaceException(nameof(executableRoot));
            }

            if (!Directory.Exists(executableRoot))
            {
                throw NotExisting(nameof(executableRoot));
            }

            string runtimesLocation = Path.Combine(executableRoot, "runtimes");

            RuntimeIdentifier[] runtimeIdentifiers = GetRuntimeIdentifiers(runtimesLocation);
            if (runtimeIdentifiers.Length == 0)
            {
                throw NoUsableRuntime(nameof(executableRoot));
            }

            RuntimeIdentifier rid = RuntimeIdentifier.OSCurrent;

            if (Array.IndexOf(runtimeIdentifiers, rid) == -1)
            {
                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    throw NoUsableRuntime(nameof(executableRoot));
                }

                if (!RuntimeIdentifier.TryParse("win-x86", out rid) || Array.IndexOf(runtimeIdentifiers, rid) == -1)
                {
                    throw NoUsableRuntime(nameof(executableRoot));
                }
            }

            string executablePath = Path.Combine(runtimesLocation, rid.ToString(), "native", executableName);

            if (!File.Exists(executablePath))
            {
                throw NoUsableRuntime(nameof(executableRoot));
            }

            return(executablePath);
        }
        private static RuntimeIdentifier[] GetRuntimeIdentifiers(string runtimesLocation)
        {
            string[] runtimeFolders       = Directory.GetDirectories(runtimesLocation, "*", SearchOption.TopDirectoryOnly);
            List <RuntimeIdentifier> rids = new List <RuntimeIdentifier>(runtimeFolders.Length);

            for (int i = 0; i < runtimeFolders.Length; i++)
            {
                if (RuntimeIdentifier.TryParse(Path.GetFileName(runtimeFolders[i]), out RuntimeIdentifier runtimeIdentifier))
                {
                    rids.Add(runtimeIdentifier);
                }
            }

            return(rids.ToArray());
        }