Example #1
0
        private static void ReadTargetFrameworkId()
        {
            string targetFrameworkMoniker = AppDomain.CurrentDomain.GetTargetFrameworkName();
            string valueInternal          = CompatibilitySwitch.GetValueInternal("TargetFrameworkMoniker");

            if (!string.IsNullOrEmpty(valueInternal))
            {
                targetFrameworkMoniker = valueInternal;
            }
            int targetFrameworkVersion = 0;
            TargetFrameworkId targetFramework;

            if (targetFrameworkMoniker == null)
            {
                targetFramework = TargetFrameworkId.Unspecified;
            }
            else if (!BinaryCompatibility.ParseTargetFrameworkMonikerIntoEnum(targetFrameworkMoniker, out targetFramework, out targetFrameworkVersion))
            {
                targetFramework = TargetFrameworkId.Unrecognized;
            }
            BinaryCompatibility.s_AppWasBuiltForFramework = targetFramework;
            BinaryCompatibility.s_AppWasBuiltForVersion   = targetFrameworkVersion;
        }
Example #2
0
        private static bool ParseTargetFrameworkMonikerIntoEnum(string targetFrameworkMoniker, out TargetFrameworkId targetFramework, out int targetFrameworkVersion)
        {
            targetFramework        = TargetFrameworkId.NotYetChecked;
            targetFrameworkVersion = 0;
            string identifier = (string)null;
            string profile    = (string)null;

            BinaryCompatibility.ParseFrameworkName(targetFrameworkMoniker, out identifier, out targetFrameworkVersion, out profile);
            if (!(identifier == ".NETFramework"))
            {
                if (!(identifier == ".NETPortable"))
                {
                    if (!(identifier == ".NETCore"))
                    {
                        if (!(identifier == "WindowsPhone"))
                        {
                            if (!(identifier == "WindowsPhoneApp"))
                            {
                                if (identifier == "Silverlight")
                                {
                                    targetFramework = TargetFrameworkId.Silverlight;
                                    if (!string.IsNullOrEmpty(profile))
                                    {
                                        if (profile == "WindowsPhone")
                                        {
                                            targetFramework        = TargetFrameworkId.Phone;
                                            targetFrameworkVersion = 70000;
                                        }
                                        else if (profile == "WindowsPhone71")
                                        {
                                            targetFramework        = TargetFrameworkId.Phone;
                                            targetFrameworkVersion = 70100;
                                        }
                                        else if (profile == "WindowsPhone8")
                                        {
                                            targetFramework        = TargetFrameworkId.Phone;
                                            targetFrameworkVersion = 80000;
                                        }
                                        else if (profile.StartsWith("WindowsPhone", StringComparison.Ordinal))
                                        {
                                            targetFramework        = TargetFrameworkId.Unrecognized;
                                            targetFrameworkVersion = 70100;
                                        }
                                        else
                                        {
                                            targetFramework = TargetFrameworkId.Unrecognized;
                                        }
                                    }
                                }
                                else
                                {
                                    targetFramework = TargetFrameworkId.Unrecognized;
                                }
                            }
                            else
                            {
                                targetFramework = TargetFrameworkId.Phone;
                            }
                        }
                        else
                        {
                            targetFramework = targetFrameworkVersion < 80100 ? TargetFrameworkId.Unspecified : TargetFrameworkId.Phone;
                        }
                    }
                    else
                    {
                        targetFramework = TargetFrameworkId.NetCore;
                    }
                }
                else
                {
                    targetFramework = TargetFrameworkId.Portable;
                }
            }
            else
            {
                targetFramework = TargetFrameworkId.NetFramework;
            }
            return(true);
        }