Exemple #1
0
        internal static long GetCompatibilityBetweenPortableLibraryAndNonPortableLibrary(FrameworkName frameworkName, FrameworkName portableFramework)
        {
            NetPortableProfile profile = NetPortableProfile.Parse(portableFramework.Profile);

            if (profile == null)
            {
                // defensive coding, this should never happen
                Debug.Assert(false, "'portableFramework' is not a valid portable framework.");
                return(0);
            }

            // among the supported frameworks by the Portable library, pick the one that is compatible with 'frameworkName'
            var compatibleFramework = profile.SupportedFrameworks.FirstOrDefault(f => IsCompatible(frameworkName, f));

            if (compatibleFramework != null)
            {
                var score = GetProfileCompatibility(frameworkName, compatibleFramework);

                // This is to ensure that if two portable frameworks have the same score,
                // we pick the one that has less number of supported platforms.
                // The *2 is to make up for the /2 to which the result of this method is subject.
                score -= (profile.SupportedFrameworks.Count * 2);

                return(score);
            }

            return(0);
        }
        internal static bool HasCompatibleProfileWith(NetPortableProfile packageFramework, FrameworkName projectOptionalFrameworkName)
        {
            List <VersionStringISetTuple> versionProfileISetTupleList = null;

            // In the dictionary _portableProfilesSetByOptionalFrameworks,
            // key is the identifier of the optional framework and value is the tuple of (optional Framework Version, set of profiles in which they are optional)
            // We try to get a value with key as projectOptionalFrameworkName.Identifier. If one exists, we check if the project version is >= the version from the retrieved tuple
            // If so, then, we see if one of the profiles, in the set from the retrieved tuple, is compatible with the packageFramework profile
            if (_portableProfilesSetByOptionalFrameworks != null &&
                _portableProfilesSetByOptionalFrameworks.TryGetValue(projectOptionalFrameworkName.Identifier, out versionProfileISetTupleList))
            {
                if (versionProfileISetTupleList != null)
                {
                    foreach (var versionProfileISetTuple in versionProfileISetTupleList)
                    {
                        if (projectOptionalFrameworkName.Version >= versionProfileISetTuple.Item1)
                        {
                            foreach (var profileName in versionProfileISetTuple.Item2)
                            {
                                NetPortableProfile profile = GetProfile(profileName);
                                if (profile != null && packageFramework.IsCompatibleWith(profile))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
        private void AddPortableProfile(NetPortableProfileTable table, NetPortableProfile profile)
        {
            if (!profile.Name.StartsWith(NetPortableProfile.ProfilePrefix, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var rawNumber = profile.Name.Substring(NetPortableProfile.ProfilePrefix.Length);
            int number;

            if (!int.TryParse(rawNumber, out number))
            {
                return;
            }

            var profileFrameworks = new KeyValuePair <int, NuGetFramework[]>(
                number,
                profile.SupportedFrameworks.Select(f => VersionUtility.GetNuGetFramework(
                                                       table,
                                                       DefaultFrameworkNameProvider.Instance,
                                                       f)).ToArray());

            _profileFrameworks.Add(profileFrameworks);

            var profileOptionalFrameworks = new KeyValuePair <int, NuGetFramework[]>(
                number,
                profile.OptionalFrameworks.Select(f => VersionUtility.GetNuGetFramework(
                                                      table,
                                                      DefaultFrameworkNameProvider.Instance,
                                                      f)).ToArray());

            _profileOptionalFrameworks.Add(profileOptionalFrameworks);
        }
Exemple #4
0
        internal static long GetCompatibilityBetweenPortableLibraryAndNonPortableLibrary(FrameworkName projectFrameworkName, FrameworkName packagePortableFramework)
        {
            NetPortableProfile packageFrameworkProfile = NetPortableProfile.Parse(packagePortableFramework.Profile, treatOptionalFrameworksAsSupportedFrameworks: true);

            if (packageFrameworkProfile == null)
            {
                // defensive coding, this should never happen
                Debug.Fail("'portableFramework' is not a valid portable framework.");
                return(long.MinValue);
            }

            // among the supported frameworks by the Portable library, pick the one that is compatible with 'projectFrameworkName'
            var compatibleFramework = packageFrameworkProfile.SupportedFrameworks.FirstOrDefault(f => IsCompatible(projectFrameworkName, f));

            if (compatibleFramework != null)
            {
                var score = GetProfileCompatibility(projectFrameworkName, compatibleFramework);

                // This is to ensure that if two portable frameworks have the same score,
                // we pick the one that has less number of supported platforms.
                // The *2 is to make up for the /2 to which the result of this method is subject.
                score -= (packageFrameworkProfile.SupportedFrameworks.Count * 2);

                return(score);
            }
            else if (NetPortableProfileTable.HasCompatibleProfileWith(packageFrameworkProfile, projectFrameworkName))
            {
                // Get the list of portable profiles that supports projectFrameworkName
                // And, see if there is atleast 1 profile which is compatible with packageFrameworkProfile
                // If so, return 0 - (packageFrameworkProfile.SupportedFrameworks.Count * 2)
                return(0 - (packageFrameworkProfile.SupportedFrameworks.Count * 2));
            }

            return(long.MinValue);
        }
Exemple #5
0
        public static string GetShortFrameworkName(FrameworkName frameworkName)
        {
            // Do a reverse lookup in _frameworkNameAlias. This is so that we can produce the more user-friendly
            // "windowsphone" string, rather than "sl3-wp". The latter one is also prohibited in portable framework's profile string.
            foreach (KeyValuePair <FrameworkName, FrameworkName> pair in _frameworkNameAlias)
            {
                // use our custom equality comparer because we want to perform case-insensitive comparison
                if (FrameworkNameEqualityComparer.Default.Equals(pair.Value, frameworkName))
                {
                    frameworkName = pair.Key;
                    break;
                }
            }

            string name;

            if (!_identifierToFrameworkFolder.TryGetValue(frameworkName.Identifier, out name))
            {
                name = frameworkName.Identifier;
            }

            // for Portable framework name, the short name has the form "portable-sl4+wp7+net45"
            string profile;

            if (name.Equals("portable", StringComparison.OrdinalIgnoreCase))
            {
                NetPortableProfile portableProfile = NetPortableProfile.Parse(frameworkName.Profile);
                if (portableProfile != null)
                {
                    profile = portableProfile.CustomProfileString;
                }
                else
                {
                    profile = frameworkName.Profile;
                }
            }
            else
            {
                // only show version part if it's > 0.0.0.0
                if (frameworkName.Version > new Version(0, 0))
                {
                    // Remove the . from versions
                    name += frameworkName.Version.ToString().Replace(".", String.Empty);
                }

                if (String.IsNullOrEmpty(frameworkName.Profile))
                {
                    return(name);
                }

                if (!_identifierToProfileFolder.TryGetValue(frameworkName.Profile, out profile))
                {
                    profile = frameworkName.Profile;
                }
            }

            return(name + "-" + profile);
        }
Exemple #6
0
        private static bool IsPortableLibraryCompatible(FrameworkName frameworkName, FrameworkName targetFrameworkName)
        {
            if (String.IsNullOrEmpty(targetFrameworkName.Profile))
            {
                return(false);
            }

            NetPortableProfile targetFrameworkPortableProfile = NetPortableProfile.Parse(targetFrameworkName.Profile);

            if (targetFrameworkPortableProfile == null)
            {
                return(false);
            }

            if (frameworkName.IsPortableFramework())
            {
                // this is the case with Portable Library vs. Portable Library
                if (String.Equals(frameworkName.Profile, targetFrameworkName.Profile, StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }

                NetPortableProfile frameworkPortableProfile = NetPortableProfile.Parse(frameworkName.Profile);
                if (frameworkPortableProfile == null)
                {
                    return(false);
                }

                return(targetFrameworkPortableProfile.IsCompatibleWith(frameworkPortableProfile));
            }
            else
            {
                // this is the case with Portable Library installed into a normal project
                bool isCompatible = targetFrameworkPortableProfile.IsCompatibleWith(frameworkName);

                if (!isCompatible)
                {
                    // TODO: Remove this logic when out dependencies have moved to ASP.NET Core 5.0
                    // as this logic is super fuzzy and terrible
                    if (string.Equals(frameworkName.Identifier, AspNetCoreFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
                    {
                        var frameworkIdentifierLookup = targetFrameworkPortableProfile.SupportedFrameworks
                                                        .Select(NormalizeFrameworkName)
                                                        .ToLookup(f => f.Identifier);

                        if (frameworkIdentifierLookup[NetFrameworkIdentifier].Any(f => f.Version >= new Version(4, 5)) &&
                            frameworkIdentifierLookup[NetCoreFrameworkIdentifier].Any(f => f.Version >= new Version(4, 5)))
                        {
                            return(true);
                        }
                    }
                }

                return(isCompatible);
            }
        }
Exemple #7
0
        internal static long GetCompatibilityBetweenPortableLibraryAndNonPortableLibrary(FrameworkName projectFrameworkName, FrameworkName packagePortableFramework, NetPortableProfileTable portableProfileTable)
        {
            NetPortableProfile packageFramework = NetPortableProfile.Parse(packagePortableFramework.get_Profile(), true, portableProfileTable);

            if (packageFramework == null)
            {
                return(-9223372036854775808L);
            }
            FrameworkName packageTargetFrameworkName = Enumerable.FirstOrDefault <FrameworkName>(packageFramework.SupportedFrameworks, (Func <FrameworkName, bool>)(f => IsCompatible(projectFrameworkName, f, portableProfileTable)));

            return((packageTargetFrameworkName == null) ? (!portableProfileTable.HasCompatibleProfileWith(packageFramework, projectFrameworkName, portableProfileTable) ? -9223372036854775808L : ((long)(0 - (packageFramework.SupportedFrameworks.Count * 2)))) : (GetProfileCompatibility(projectFrameworkName, packageTargetFrameworkName, portableProfileTable) - (packageFramework.SupportedFrameworks.Count * 2)));
        }
Exemple #8
0
        /// <summary>
        /// Attempt to calculate how compatible a portable framework folder is to a portable project.
        /// The two portable frameworks passed to this method MUST be compatible with each other.
        /// </summary>
        /// <remarks>
        /// The returned score will be negative value.
        /// </remarks>
        internal static int GetCompatibilityBetweenPortableLibraryAndPortableLibrary(FrameworkName frameworkName, FrameworkName targetFrameworkName)
        {
            // Algorithms: Give a score from 0 to N indicating how close *in version* each package platform is the project’s platforms
            // and then choose the folder with the lowest score. If the score matches, choose the one with the least platforms.
            //
            // For example:
            //
            // Project targeting: .NET 4.5 + SL5 + WP71
            //
            // Package targeting:
            // .NET 4.5 (0) + SL5 (0) + WP71 (0)                            == 0
            // .NET 4.5 (0) + SL5 (0) + WP71 (0) + Win8 (0)                 == 0
            // .NET 4.5 (0) + SL4 (1) + WP71 (0) + Win8 (0)                 == 1
            // .NET 4.0 (1) + SL4 (1) + WP71 (0) + Win8 (0)                 == 2
            // .NET 4.0 (1) + SL4 (1) + WP70 (1) + Win8 (0)                 == 3
            //
            // Above, there’s two matches with the same result, choose the one with the least amount of platforms.
            //
            // There will be situations, however, where there is still undefined behavior, such as:
            //
            // .NET 4.5 (0) + SL4 (1) + WP71 (0)                            == 1
            // .NET 4.0 (1) + SL5 (0) + WP71 (0)                            == 1

            NetPortableProfile frameworkProfile = NetPortableProfile.Parse(frameworkName.Profile);

            Debug.Assert(frameworkName != null);

            NetPortableProfile targetFrameworkProfile = NetPortableProfile.Parse(targetFrameworkName.Profile);

            Debug.Assert(targetFrameworkName != null);

            int score = 0;

            foreach (var framework in targetFrameworkProfile.SupportedFrameworks)
            {
                var matchingFramework = frameworkProfile.SupportedFrameworks.FirstOrDefault(f => IsCompatible(f, framework));
                if (matchingFramework != null && matchingFramework.Version > framework.Version)
                {
                    score++;
                }
            }

            // This is to ensure that if two portable frameworks have the same score,
            // we pick the one that has less number of supported platforms.
            score = score * 50 + targetFrameworkProfile.SupportedFrameworks.Count;

            // Our algorithm returns lowest score for the most compatible framework.
            // However, the caller of this method expects it to have the highest score.
            // Hence, we return the negative value of score here.
            return(-score);
        }
Exemple #9
0
        public NetPortableProfile GetProfile(string profileName)
        {
            if (string.IsNullOrEmpty(profileName))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "profileName");
            }
            if (this.Profiles.Contains(profileName))
            {
                return(this.Profiles[profileName]);
            }
            NetPortableProfile profile = null;

            this._portableProfilesByCustomProfileString.TryGetValue(profileName, out profile);
            return(profile);
        }
Exemple #10
0
        internal static int GetCompatibilityBetweenPortableLibraryAndNonPortableLibrary(FrameworkName frameworkName, FrameworkName portableFramework)
        {
            NetPortableProfile profile = NetPortableProfile.Parse(portableFramework.Profile);

            if (profile == null)
            {
                // defensive coding, this should never happen
                Debug.Fail("'portableFramework' is not a valid portable framework.");
                return(0);
            }

            // among the supported frameworks by the Portable library, pick the one that is compatible with 'frameworkName'
            var compatibleFramework = profile.SupportedFrameworks.FirstOrDefault(f => VersionUtility.IsCompatible(frameworkName, f));

            return(compatibleFramework == null ? 0 : GetProfileCompatibility(frameworkName, compatibleFramework));
        }
Exemple #11
0
 private static Version GetEffectiveFrameworkVersion(FrameworkName projectFramework, FrameworkName targetFrameworkVersion, NetPortableProfileTable portableProfileTable)
 {
     if (targetFrameworkVersion.IsPortableFramework())
     {
         NetPortableProfile profile = NetPortableProfile.Parse(targetFrameworkVersion.get_Profile(), false, portableProfileTable);
         if (profile != null)
         {
             FrameworkName name = Enumerable.FirstOrDefault <FrameworkName>(profile.SupportedFrameworks, (Func <FrameworkName, bool>)(f => IsCompatible(projectFramework, f, portableProfileTable)));
             if (name != null)
             {
                 return(name.get_Version());
             }
         }
     }
     return(targetFrameworkVersion.get_Version());
 }
Exemple #12
0
        public static string GetShortFrameworkName(FrameworkName frameworkName, NetPortableProfileTable portableProfileTable)
        {
            string str;
            string str2;

            if (frameworkName == null)
            {
                throw new ArgumentNullException("frameworkName");
            }
            foreach (KeyValuePair <FrameworkName, FrameworkName> pair in _frameworkNameAlias)
            {
                if (FrameworkNameEqualityComparer.Default.Equals(pair.Value, frameworkName))
                {
                    frameworkName = pair.Key;
                    break;
                }
            }
            if (!_identifierToFrameworkFolder.TryGetValue(frameworkName.get_Identifier(), out str))
            {
                str = frameworkName.get_Identifier();
            }
            if (str.Equals("portable", StringComparison.OrdinalIgnoreCase))
            {
                if (portableProfileTable == null)
                {
                    throw new ArgumentException(NuGetResources.PortableProfileTableMustBeSpecified, "portableProfileTable");
                }
                NetPortableProfile profile = NetPortableProfile.Parse(frameworkName.get_Profile(), false, portableProfileTable);
                str2 = (profile == null) ? frameworkName.get_Profile() : profile.CustomProfileString;
            }
            else
            {
                if (frameworkName.get_Version() > new Version())
                {
                    str = str + frameworkName.get_Version().ToString().Replace(".", string.Empty);
                }
                if (string.IsNullOrEmpty(frameworkName.get_Profile()))
                {
                    return(str);
                }
                if (!_identifierToProfileFolder.TryGetValue(frameworkName.get_Profile(), out str2))
                {
                    str2 = frameworkName.get_Profile();
                }
            }
            return(str + "-" + str2);
        }
Exemple #13
0
        private static Version GetEffectiveFrameworkVersion(FrameworkName projectFramework, FrameworkName targetFrameworkVersion)
        {
            if (targetFrameworkVersion.IsPortableFramework())
            {
                NetPortableProfile profile = NetPortableProfile.Parse(targetFrameworkVersion.Profile);
                if (profile != null)
                {
                    // if it's a portable library, return the version of the matching framework
                    var compatibleFramework = profile.SupportedFrameworks.FirstOrDefault(f => VersionUtility.IsCompatible(projectFramework, f));
                    if (compatibleFramework != null)
                    {
                        return(compatibleFramework.Version);
                    }
                }
            }

            return(targetFrameworkVersion.Version);
        }
Exemple #14
0
        internal bool HasCompatibleProfileWith(NetPortableProfile packageFramework, FrameworkName projectOptionalFrameworkName, NetPortableProfileTable portableProfileTable)
        {
            List <Tuple <Version, ISet <string> > > list = null;

            if ((this._portableProfilesSetByOptionalFrameworks != null) && this._portableProfilesSetByOptionalFrameworks.TryGetValue(projectOptionalFrameworkName.get_Identifier(), out list))
            {
                using (List <Tuple <Version, ISet <string> > > .Enumerator enumerator = list.GetEnumerator())
                {
                    while (true)
                    {
                        if (!enumerator.MoveNext())
                        {
                            break;
                        }
                        Tuple <Version, ISet <string> > current = enumerator.Current;
                        if (projectOptionalFrameworkName.get_Version() >= current.Item1)
                        {
                            using (IEnumerator <string> enumerator2 = current.Item2.GetEnumerator())
                            {
                                while (true)
                                {
                                    if (!enumerator2.MoveNext())
                                    {
                                        break;
                                    }
                                    string             profileName             = enumerator2.Current;
                                    NetPortableProfile projectFrameworkProfile = this.GetProfile(profileName);
                                    if ((projectFrameworkProfile != null) && packageFramework.IsCompatibleWith(projectFrameworkProfile, portableProfileTable))
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
        private static bool IsPortableLibraryCompatible(
            NetPortableProfileTable table,
            FrameworkName projectFrameworkName,
            FrameworkName packageTargetFrameworkName)
        {
            if (string.IsNullOrEmpty(packageTargetFrameworkName.Profile))
            {
                return(false);
            }

            NetPortableProfile targetFrameworkPortableProfile = NetPortableProfile.Parse(table, packageTargetFrameworkName.Profile);

            if (targetFrameworkPortableProfile == null)
            {
                return(false);
            }

            if (projectFrameworkName.IsPortableFramework())
            {
                // this is the case with Portable Library vs. Portable Library
                if (string.Equals(projectFrameworkName.Profile, packageTargetFrameworkName.Profile, StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }

                NetPortableProfile frameworkPortableProfile = NetPortableProfile.Parse(table, projectFrameworkName.Profile);
                if (frameworkPortableProfile == null)
                {
                    return(false);
                }

                return(targetFrameworkPortableProfile.IsCompatibleWith(frameworkPortableProfile));
            }
            else
            {
                // this is the case with Portable Library installed into a normal project
                return(targetFrameworkPortableProfile.IsCompatibleWith(table, projectFrameworkName));
            }
        }
Exemple #16
0
        public static NetPortableProfile GetProfile(string profileName)
        {
            if (String.IsNullOrEmpty(profileName))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "profileName");
            }

            // Original behavior fully preserved, as we first try the original behavior.
            // NOTE: this could be a single TryGetValue if this collection was kept as a dictionary...
            if (Profiles.Contains(profileName))
            {
                return(Profiles[profileName]);
            }

            // If we didn't get a profile by the simple profile name, try now with
            // the custom profile string (i.e. "net40-client")
            NetPortableProfile result = null;

            _portableProfilesByCustomProfileString.TryGetValue(profileName, out result);

            return(result);
        }
Exemple #17
0
        private static bool IsPortableLibraryCompatible(FrameworkName projectFrameworkName, FrameworkName packageTargetFrameworkName, NetPortableProfileTable portableProfileTable)
        {
            if (string.IsNullOrEmpty(packageTargetFrameworkName.get_Profile()))
            {
                return(false);
            }
            NetPortableProfile profile = NetPortableProfile.Parse(packageTargetFrameworkName.get_Profile(), false, portableProfileTable);

            if (profile == null)
            {
                return(false);
            }
            if (!projectFrameworkName.IsPortableFramework())
            {
                return(profile.IsCompatibleWith(projectFrameworkName));
            }
            if (string.Equals(projectFrameworkName.get_Profile(), packageTargetFrameworkName.get_Profile(), StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }
            NetPortableProfile projectFrameworkProfile = NetPortableProfile.Parse(projectFrameworkName.get_Profile(), false, portableProfileTable);

            return((projectFrameworkProfile != null) ? profile.IsCompatibleWith(projectFrameworkProfile, portableProfileTable) : false);
        }
Exemple #18
0
        /// <summary>
        /// Attempt to calculate how compatible a portable framework folder is to a portable project.
        /// The two portable frameworks passed to this method MUST be compatible with each other.
        /// </summary>
        /// <remarks>
        /// The returned score will be negative value.
        /// </remarks>
        internal static int GetCompatibilityBetweenPortableLibraryAndPortableLibrary(FrameworkName projectFrameworkName, FrameworkName packageTargetFrameworkName)
        {
            // Algorithms: Give a score from 0 to N indicating how close *in version* each package platform is the project’s platforms
            // and then choose the folder with the lowest score. If the score matches, choose the one with the least platforms.
            //
            // For example:
            //
            // Project targeting: .NET 4.5 + SL5 + WP71
            //
            // Package targeting:
            // .NET 4.5 (0) + SL5 (0) + WP71 (0)                            == 0
            // .NET 4.5 (0) + SL5 (0) + WP71 (0) + Win8 (0)                 == 0
            // .NET 4.5 (0) + SL4 (1) + WP71 (0) + Win8 (0)                 == 1
            // .NET 4.0 (1) + SL4 (1) + WP71 (0) + Win8 (0)                 == 2
            // .NET 4.0 (1) + SL4 (1) + WP70 (1) + Win8 (0)                 == 3
            //
            // Above, there’s two matches with the same result, choose the one with the least amount of platforms.
            //
            // There will be situations, however, where there is still undefined behavior, such as:
            //
            // .NET 4.5 (0) + SL4 (1) + WP71 (0)                            == 1
            // .NET 4.0 (1) + SL5 (0) + WP71 (0)                            == 1

            NetPortableProfile projectFrameworkProfile = NetPortableProfile.Parse(projectFrameworkName.Profile);

            Debug.Assert(projectFrameworkProfile != null);

            NetPortableProfile packageTargetFrameworkProfile = NetPortableProfile.Parse(packageTargetFrameworkName.Profile, treatOptionalFrameworksAsSupportedFrameworks: true);

            Debug.Assert(packageTargetFrameworkProfile != null);

            int nonMatchingCompatibleFrameworkCount = 0;
            int inCompatibleOptionalFrameworkCount  = 0;

            foreach (var supportedPackageTargetFramework in packageTargetFrameworkProfile.SupportedFrameworks)
            {
                var compatibleProjectFramework = projectFrameworkProfile.SupportedFrameworks.FirstOrDefault(f => IsCompatible(f, supportedPackageTargetFramework));
                if (compatibleProjectFramework != null && compatibleProjectFramework.Version > supportedPackageTargetFramework.Version)
                {
                    nonMatchingCompatibleFrameworkCount++;
                }
            }

            foreach (var optionalProjectFramework in projectFrameworkProfile.OptionalFrameworks)
            {
                var compatiblePackageTargetFramework = packageTargetFrameworkProfile.SupportedFrameworks.FirstOrDefault(f => IsCompatible(f, optionalProjectFramework));
                if (compatiblePackageTargetFramework == null || compatiblePackageTargetFramework.Version > optionalProjectFramework.Version)
                {
                    inCompatibleOptionalFrameworkCount++;
                }
                else if (compatiblePackageTargetFramework != null && compatiblePackageTargetFramework.Version < optionalProjectFramework.Version)
                {
                    // we check again if the package version < project version, because, if they are equal, they are matching compatible frameworks
                    // neither inCompatibleOptionalFrameworkCount nor nonMatchingCompatibleFrameworkCount should be incremented
                    nonMatchingCompatibleFrameworkCount++;
                }
            }

            // The following is the maximum project framework count which is also the maximum possible incompatibilities
            int maxPossibleIncompatibleFrameworkCount = 1 + projectFrameworkProfile.SupportedFrameworks.Count + projectFrameworkProfile.OptionalFrameworks.Count;

            // This is to ensure that profile with compatible optional frameworks wins over profiles without, even, when supported frameworks are highly compatible
            // If there are no incompatible optional frameworks, the score below will be simply nonMatchingCompatibleFrameworkCount
            // For example, Let Project target net45+sl5+monotouch+monoandroid. And, Package has 4 profiles, (THIS EXAMPLE IS LIKELY NOT A REAL_WORLD SCENARIO :))
            // A: net45+sl5, B: net40+sl5+monotouch, C: net40+sl4+monotouch+monoandroid, D: net40+sl4+monotouch+monoandroid+wp71
            // At this point, Compatibility is as follows. C = D > B > A. Scores for A = (5 * 2 + 0), B = (5 * 1 + 1), C = (5 * 0 + 2), D = (5 * 0 + 2)
            // The scores are 10, 6, 2 and 2. Both C and D are the most compatible with a score of 2
            // Clearly, having more number of frameworks, supported and optional, that are compatible is preferred over most compatible supported frameworks alone
            int score = maxPossibleIncompatibleFrameworkCount * inCompatibleOptionalFrameworkCount +
                        nonMatchingCompatibleFrameworkCount;

            // This is to ensure that if two portable frameworks have the same score,
            // we pick the one that has less number of supported platforms.
            // In the example described in comments above, both C and D had an equal score of 2. With the following correction, new scores are as follows
            // A = (10 * 50 + 2), B = (6 * 50 + 3), C = (2 * 50 + 4), D = (2 * 50 + 5)
            // A = 502, B = 303, C = 104, D = 105. And, C has the lowest score and the most compatible
            score = score * 50 + packageTargetFrameworkProfile.SupportedFrameworks.Count;

            // Our algorithm returns lowest score for the most compatible framework.
            // However, the caller of this method expects it to have the highest score.
            // Hence, we return the negative value of score here.
            return(-score);
        }
        internal static string GetShortFrameworkName(NetPortableProfileTable table, FrameworkName frameworkName)
        {
            if (frameworkName == null)
            {
                throw new ArgumentNullException("frameworkName");
            }

            // Do a reverse lookup in _frameworkNameAlias. This is so that we can produce the more user-friendly
            // "windowsphone" string, rather than "sl3-wp". The latter one is also prohibited in portable framework's profile string.
            foreach (KeyValuePair <FrameworkName, FrameworkName> pair in _frameworkNameAlias)
            {
                // use our custom equality comparer because we want to perform case-insensitive comparison
                if (FrameworkNameEqualityComparer.Default.Equals(pair.Value, frameworkName))
                {
                    frameworkName = pair.Key;
                    break;
                }
            }

            if (frameworkName.Version.Major == 5 &&
                frameworkName.Version.Minor == 0 &&
                frameworkName.Identifier.Equals(NetPlatformFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
            {
                // Normalize version 5.0 to 0.0 for display purposes for dotnet
                frameworkName = new FrameworkName(frameworkName.Identifier, _emptyVersion, frameworkName.Profile);
            }

            string name;

            if (!_identifierToFrameworkFolder.TryGetValue(frameworkName.Identifier, out name))
            {
                name = frameworkName.Identifier;
            }

            // for Portable framework name, the short name has the form "portable-sl4+wp7+net45"
            string profile;

            if (name.Equals("portable", StringComparison.OrdinalIgnoreCase))
            {
                var portableProfile = NetPortableProfile.Parse(
                    table,
                    frameworkName.Profile);

                if (portableProfile != null)
                {
                    profile = portableProfile.CustomProfileString;
                }
                else
                {
                    profile = frameworkName.Profile;
                }
            }
            else
            {
                // only show version part if it's > 0.0.0.0
                if (frameworkName.Version > new Version())
                {
                    // Remove the . from versions
                    if (RequiresDecimalVersioning(frameworkName.Version))
                    {
                        // This version has digits over 10 and must be expressed using decimals
                        name += GetDecimalVersionString(frameworkName.Version);
                    }
                    else
                    {
                        if (frameworkName.Identifier.Equals(NetStandardAppFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) ||
                            frameworkName.Identifier.Equals(NetStandardFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) ||
                            frameworkName.Identifier.Equals(NetPlatformFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) ||
                            frameworkName.Identifier.Equals(NetCoreAppFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
                        {
                            // do not remove the . from versions for dotnet/netstandard(app)/netcoreapp frameworks
                            name += frameworkName.Version.ToString();
                        }
                        else
                        {
                            // remove the . from versions
                            name += frameworkName.Version.ToString().Replace(".", string.Empty);
                        }
                    }
                }

                if (String.IsNullOrEmpty(frameworkName.Profile))
                {
                    return(name);
                }

                if (!_identifierToProfileFolder.TryGetValue(frameworkName.Profile, out profile))
                {
                    profile = frameworkName.Profile;
                }
            }

            return(name + "-" + profile);
        }