/// <summary>
 /// The setter should only ever be used by tests.
 /// </summary>
 internal static void SetProfileCollection(NetPortableProfileCollection profileCollection)
 {
     if (profileCollection == null)
     {
         _instance = null;
     }
     else
     {
         _instance = new NetPortableProfileTable(profileCollection);
     }
 }
        public bool IsCompatibleWith(NetPortableProfile projectFrameworkProfile, NetPortableProfileTable portableProfileTable)
        {
            if (projectFrameworkProfile == null)
            {
                throw new ArgumentNullException("projectFrameworkProfile");
            }

            return(projectFrameworkProfile.SupportedFrameworks.All(
                       projectFramework => this.SupportedFrameworks.Any(
                           packageFramework => VersionUtility.IsCompatible(projectFramework, packageFramework, portableProfileTable))));
        }
        internal static NuGetFramework GetNuGetFramework(
            NetPortableProfileTable table,
            IFrameworkNameProvider provider,
            FrameworkName framework)
        {
            // Use the short folder name as the common format between FrameworkName and
            // NuGetFramework. With portable frameworks, there are differences in
            // FrameworkName and NuGetFramework.DotNetFrameworkName.
            var folderName = GetShortFrameworkName(table, framework);

            return(NuGetFramework.ParseFolder(folderName, provider));
        }
 internal static void Serialize(NetPortableProfileTable portableProfileTable, Stream output)
 {
     // We need to convert the profile entries to surrogates to make them easily and simply serializable
     var surrogates = portableProfileTable.Profiles.Select(p => new PortableProfile()
     {
         Name = p.Name,
         FrameworkVersion = p.FrameworkVersion,
         SupportedFrameworks = p.SupportedFrameworks.Select(f => f.FullName).ToArray(),
         OptionalFrameworks = p.OptionalFrameworks.Select(f => f.FullName).ToArray()
     });
     _serializer.WriteObject(output, surrogates);
 }
예제 #5
0
        internal static void Serialize(NetPortableProfileTable portableProfileTable, Stream output)
        {
            // We need to convert the profile entries to surrogates to make them easily and simply serializable
            var surrogates = portableProfileTable.Profiles.Select(p => new PortableProfile()
            {
                Name                = p.Name,
                FrameworkVersion    = p.FrameworkVersion,
                SupportedFrameworks = p.SupportedFrameworks.Select(f => f.FullName).ToArray(),
                OptionalFrameworks  = p.OptionalFrameworks.Select(f => f.FullName).ToArray()
            });

            _serializer.WriteObject(output, surrogates);
        }
예제 #6
0
        internal static void Serialize(NetPortableProfileTable portableProfileTable, Stream output)
        {
            IEnumerable <PortableProfile> graph = Enumerable.Select <NetPortableProfile, PortableProfile>(portableProfileTable.Profiles, delegate(NetPortableProfile p) {
                PortableProfile profile1     = new PortableProfile();
                profile1.Name                = p.Name;
                profile1.FrameworkVersion    = p.FrameworkVersion;
                profile1.SupportedFrameworks = (from f in p.SupportedFrameworks select f.get_FullName()).ToArray <string>();
                PortableProfile local3       = profile1;
                PortableProfile local4       = profile1;
                local4.OptionalFrameworks    = (from f in p.OptionalFrameworks select f.get_FullName()).ToArray <string>();
                return(local4);
            });

            _serializer.WriteObject(output, graph);
        }
예제 #7
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);
        }
예제 #8
0
        /// <summary>
        /// Attempt to parse a profile string into an instance of <see cref="NetPortableProfile"/>.
        /// The profile string can be either ProfileXXX or sl4+net45+wp7
        /// </summary>
        public static NetPortableProfile Parse(string profileValue)
        {
            if (String.IsNullOrEmpty(profileValue))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "profileValue");
            }

            if (profileValue.StartsWith("Profile", StringComparison.OrdinalIgnoreCase))
            {
                return(NetPortableProfileTable.GetProfile(profileValue));
            }

            VersionUtility.ValidatePortableFrameworkProfilePart(profileValue);

            var supportedFrameworks = profileValue.Split(new [] { '+' }, StringSplitOptions.RemoveEmptyEntries)
                                      .Select(VersionUtility.ParseFrameworkName);

            return(new NetPortableProfile(profileValue, supportedFrameworks));
        }
        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));
            }
        }
예제 #10
0
        /// <summary>
        /// Attempt to parse a profile string into an instance of <see cref="NetPortableProfile"/>.
        /// The profile string can be either ProfileXXX or sl4+net45+wp7
        /// </summary>
        public static NetPortableProfile Parse(NetPortableProfileTable table, string profileValue, bool treatOptionalFrameworksAsSupportedFrameworks = false)
        {
            if (String.IsNullOrEmpty(profileValue))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "profileValue");
            }

            // Previously, only the full "ProfileXXX" long .NET name could be used for this method.
            // This was inconsistent with the way the "custom profile string" (like "sl4+net45+wp7")
            // was supported in other places. By fixing the way the profile table indexes the cached
            // profiles, we can now indeed access by either naming, so we don't need the old check
            // for the string starting with "Profile".
            var result = table.GetProfile(profileValue);

            if (result != null)
            {
                if (treatOptionalFrameworksAsSupportedFrameworks)
                {
                    result = new NetPortableProfile(result.Name, result.SupportedFrameworks.Concat(result.OptionalFrameworks));
                }

                return(result);
            }

            if (profileValue.StartsWith(ProfilePrefix, StringComparison.OrdinalIgnoreCase))
            {
                // This can happen if profileValue is an unrecognized profile, or
                // for some rare cases, the Portable Profile files are missing on disk.
                return(null);
            }

            VersionUtility.ValidatePortableFrameworkProfilePart(profileValue);

            var supportedFrameworks = profileValue.Split(new [] { '+' }, StringSplitOptions.RemoveEmptyEntries)
                                      .Select(VersionUtility.ParseFrameworkName);

            return(new NetPortableProfile(profileValue, supportedFrameworks));
        }
        internal static bool IsCompatible(
            NetPortableProfileTable table,
            IFrameworkCompatibilityProvider compatibilityProvider,
            IFrameworkNameProvider nameProvider,
            FrameworkName projectFrameworkName,
            FrameworkName packageTargetFrameworkName)
        {
            if (projectFrameworkName == null)
            {
                return(true);
            }

            var projectNuGetFramework = GetNuGetFramework(
                table,
                nameProvider,
                projectFrameworkName);

            var packageTargetNuGetFramework = GetNuGetFramework(
                table,
                nameProvider,
                packageTargetFrameworkName);

            var isCompatible = compatibilityProvider.IsCompatible(
                projectNuGetFramework,
                packageTargetNuGetFramework);

            // Fallback to legacy portable compatibility logic if both:
            //   a) the modern compatibility code returns false
            //   b) the package framework is portable
            if (!isCompatible && packageTargetFrameworkName.IsPortableFramework())
            {
                return(IsPortableLibraryCompatible(table, projectFrameworkName, packageTargetFrameworkName));
            }

            return(isCompatible);
        }
예제 #12
0
        internal static bool IsCompatible(FrameworkName projectFrameworkName, FrameworkName packageTargetFrameworkName, NetPortableProfileTable portableProfileTable)
        {
            Dictionary <string, string[]> dictionary;

            string[] strArray;
            if (projectFrameworkName == null)
            {
                return(true);
            }
            if (packageTargetFrameworkName.IsPortableFramework())
            {
                return(IsPortableLibraryCompatible(projectFrameworkName, packageTargetFrameworkName, portableProfileTable));
            }
            packageTargetFrameworkName = NormalizeFrameworkName(packageTargetFrameworkName);
            projectFrameworkName       = NormalizeFrameworkName(projectFrameworkName);
            if (!projectFrameworkName.get_Identifier().Equals(packageTargetFrameworkName.get_Identifier(), StringComparison.OrdinalIgnoreCase))
            {
                FrameworkName name;
                if (!_equivalentProjectFrameworks.TryGetValue(projectFrameworkName.get_Identifier(), out name) || !name.get_Identifier().Equals(packageTargetFrameworkName.get_Identifier(), StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
                projectFrameworkName = name;
            }
            return((NormalizeVersion(projectFrameworkName.get_Version()) >= NormalizeVersion(packageTargetFrameworkName.get_Version())) ? (!string.Equals(projectFrameworkName.get_Profile(), packageTargetFrameworkName.get_Profile(), StringComparison.OrdinalIgnoreCase) ? (_compatibiltyMapping.TryGetValue(projectFrameworkName.get_Identifier(), out dictionary) && (dictionary.TryGetValue(packageTargetFrameworkName.get_Profile(), out strArray) && strArray.Contains <string>(projectFrameworkName.get_Profile(), StringComparer.OrdinalIgnoreCase))) : true) : false);
        }
예제 #13
0
 public static bool IsCompatible(FrameworkName projectFrameworkName, IEnumerable <FrameworkName> packageSupportedFrameworks, NetPortableProfileTable portableProfileTable) =>
 (!packageSupportedFrameworks.Any <FrameworkName>() || Enumerable.Any <FrameworkName>(packageSupportedFrameworks, (Func <FrameworkName, bool>)(packageSupportedFramework => IsCompatible(projectFrameworkName, packageSupportedFramework, portableProfileTable))));
예제 #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);
        }
예제 #15
0
        private static long GetProfileCompatibility(FrameworkName projectFrameworkName, FrameworkName packageTargetFrameworkName, NetPortableProfileTable portableProfileTable)
        {
            projectFrameworkName       = NormalizeFrameworkName(projectFrameworkName);
            packageTargetFrameworkName = NormalizeFrameworkName(packageTargetFrameworkName);
            if (packageTargetFrameworkName.IsPortableFramework())
            {
                return(!projectFrameworkName.IsPortableFramework() ? (GetCompatibilityBetweenPortableLibraryAndNonPortableLibrary(projectFrameworkName, packageTargetFrameworkName, portableProfileTable) / 2L) : ((long)GetCompatibilityBetweenPortableLibraryAndPortableLibrary(projectFrameworkName, packageTargetFrameworkName, portableProfileTable)));
            }
            long num = 0L + CalculateVersionDistance(projectFrameworkName.get_Version(), GetEffectiveFrameworkVersion(projectFrameworkName, packageTargetFrameworkName, portableProfileTable));

            if (packageTargetFrameworkName.get_Profile().Equals(projectFrameworkName.get_Profile(), StringComparison.OrdinalIgnoreCase))
            {
                num += 1L;
            }
            if (packageTargetFrameworkName.get_Identifier().Equals(projectFrameworkName.get_Identifier(), StringComparison.OrdinalIgnoreCase))
            {
                num += 0xa00000000L;
            }
            return(num);
        }
예제 #16
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());
 }
예제 #17
0
        internal static int GetCompatibilityBetweenPortableLibraryAndPortableLibrary(FrameworkName projectFrameworkName, FrameworkName packageTargetFrameworkName, NetPortableProfileTable portableProfileTable)
        {
            NetPortableProfile profile  = NetPortableProfile.Parse(projectFrameworkName.get_Profile(), false, portableProfileTable);
            NetPortableProfile profile2 = NetPortableProfile.Parse(packageTargetFrameworkName.get_Profile(), true, portableProfileTable);
            int num  = 0;
            int num2 = 0;

            foreach (FrameworkName supportedPackageTargetFramework in profile2.SupportedFrameworks)
            {
                FrameworkName name = Enumerable.FirstOrDefault <FrameworkName>(profile.SupportedFrameworks, (Func <FrameworkName, bool>)(f => IsCompatible(f, supportedPackageTargetFramework, portableProfileTable)));
                if ((name != null) && (name.get_Version() > supportedPackageTargetFramework.get_Version()))
                {
                    num++;
                }
            }
            foreach (FrameworkName optionalProjectFramework in profile.OptionalFrameworks)
            {
                FrameworkName name2 = Enumerable.FirstOrDefault <FrameworkName>(profile2.SupportedFrameworks, (Func <FrameworkName, bool>)(f => IsCompatible(f, optionalProjectFramework, portableProfileTable)));
                if ((name2 == null) || (name2.get_Version() > optionalProjectFramework.get_Version()))
                {
                    num2++;
                    continue;
                }
                if ((name2 != null) && (name2.get_Version() < optionalProjectFramework.get_Version()))
                {
                    num++;
                }
            }
            return(-((((((1 + profile.SupportedFrameworks.Count) + profile.OptionalFrameworks.Count) * num2) + num) * 50) + profile2.SupportedFrameworks.Count));
        }
예제 #18
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)));
        }
        /// <summary>
        /// This method uses the 'targetFramework' attribute in the packages.config to determine compatible items.
        /// Hence, it's only good for uninstall operations.
        /// </summary>
        private IEnumerable <T> GetCompatibleInstalledItemsForPackage <T>(string packageId, IEnumerable <T> items, NetPortableProfileTable portableProfileTable) where T : IFrameworkTargetable
        {
            FrameworkName packageFramework = ProjectManagerExtensions.GetTargetFrameworkForPackage(this, packageId);

            if (packageFramework == null)
            {
                return(items);
            }

            IEnumerable <T> compatibleItems;

            if (VersionUtility.TryGetCompatibleItems(packageFramework, items, portableProfileTable, out compatibleItems))
            {
                return(compatibleItems);
            }
            return(Enumerable.Empty <T>());
        }
        internal bool HasCompatibleProfileWith(NetPortableProfile packageFramework, FrameworkName projectOptionalFrameworkName, NetPortableProfileTable portableProfileTable)
        {
            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))
            {
                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, portableProfileTable))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
예제 #21
0
        internal bool HasCompatibleProfileWith(NetPortableProfile packageFramework, FrameworkName projectOptionalFrameworkName, NetPortableProfileTable portableProfileTable)
        {
            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))
            {
                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, portableProfileTable))
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }
예제 #22
0
        private IEnumerable <T> GetCompatibleInstalledItemsForPackage <T>(string packageId, IEnumerable <T> items, NetPortableProfileTable portableProfileTable) where T : IFrameworkTargetable
        {
            IEnumerable <T> enumerable;
            FrameworkName   targetFrameworkForPackage = this.GetTargetFrameworkForPackage(packageId);

            return((targetFrameworkForPackage != null) ? (!VersionUtility.TryGetCompatibleItems <T>(targetFrameworkForPackage, items, portableProfileTable, out enumerable) ? Enumerable.Empty <T>() : enumerable) : items);
        }
예제 #23
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);
        }
        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);
        }
예제 #25
0
        public static bool TryGetCompatibleItems <T>(FrameworkName projectFramework, IEnumerable <T> items, NetPortableProfileTable portableProfileTable, out IEnumerable <T> compatibleItems) where T : IFrameworkTargetable
        {
            if (!items.Any <T>())
            {
                compatibleItems = Enumerable.Empty <T>();
                return(true);
            }
            FrameworkName internalProjectFramework    = projectFramework ?? EmptyFramework;
            List <IGrouping <FrameworkName, T> > list = (from <> h__TransparentIdentifier0 in from item in items select new {
                item = item,
                frameworks = ((item.SupportedFrameworks == null) || !item.SupportedFrameworks.Any <FrameworkName>()) ? new FrameworkName[1] : item.SupportedFrameworks
            }
                                                         from framework in < > h__TransparentIdentifier0.frameworks
                                                         select new {
                Item = < > h__TransparentIdentifier0.item,
                TargetFramework = framework
            } into g
                                                         group g.Item by g.TargetFramework).ToList <IGrouping <FrameworkName, T> >();

            compatibleItems = (from g in list
                               where (g.Key != null) && IsCompatible(internalProjectFramework, g.Key, portableProfileTable)
                               orderby GetProfileCompatibility(internalProjectFramework, g.Key, portableProfileTable) descending
                               select g).FirstOrDefault <IGrouping <FrameworkName, T> >();
            bool flag = (compatibleItems != null) && compatibleItems.Any <T>();

            if (!flag)
            {
                compatibleItems = from g in list
                                  where g.Key == null
                                  select g;
                flag = (compatibleItems != null) && compatibleItems.Any <T>();
            }
            if (!flag)
            {
                compatibleItems = null;
            }
            return(flag);
        }
예제 #26
0
        public static NetPortableProfile Parse(string profileValue, bool treatOptionalFrameworksAsSupportedFrameworks = false, NetPortableProfileTable portableProfileTable = null)
        {
            portableProfileTable = portableProfileTable ?? NetPortableProfileTable.Default;
            if (string.IsNullOrEmpty(profileValue))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "profileValue");
            }
            NetPortableProfile profile = portableProfileTable.GetProfile(profileValue);

            if (profile != null)
            {
                if (treatOptionalFrameworksAsSupportedFrameworks)
                {
                    profile = new NetPortableProfile(profile.Name, profile.SupportedFrameworks.Concat <FrameworkName>(profile.OptionalFrameworks), null);
                }
                return(profile);
            }
            if (profileValue.StartsWith("Profile", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }
            VersionUtility.ValidatePortableFrameworkProfilePart(profileValue);
            char[] separator = new char[] { '+' };
            return(new NetPortableProfile(profileValue, Enumerable.Select <string, FrameworkName>(profileValue.Split(separator, StringSplitOptions.RemoveEmptyEntries), new Func <string, FrameworkName>(VersionUtility.ParseFrameworkName)), null));
        }