Пример #1
0
        protected bool TryDetectFramework4Upgrade(ModuleDefinition module, out FrameworkVersion frameworkVersion)
        {
            frameworkVersion = FrameworkVersion.Unknown;
            if (module.IsMain)
            {
                FrameworkName frameworkName;
                if (TryGetTargetFrameworkName(module.Assembly.TargetFrameworkAttributeValue, out frameworkName) &&
                    TryParseFramework4Name(frameworkName.Version.ToString(), out frameworkVersion))
                {
                    return(true);
                }
                else
                {
                    bool isInFrameworkDir;
                    if (IsFramework4Assembly(module.Assembly, out isInFrameworkDir))
                    {
                        if (isInFrameworkDir)
                        {
                            frameworkVersion = Framework4VersionResolver.GetInstalledFramework4Version();
                        }
                        else
                        {
                            frameworkVersion = Framework4VersionResolver.GetFrameworkVersionByFileVersion(module.Assembly.MainModule.FilePath);
                        }

                        if (frameworkVersion != FrameworkVersion.Unknown)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Пример #2
0
        protected bool TryDetectFramework4Upgrade(ModuleDefinition module, out FrameworkVersion frameworkVersion)
        {
            frameworkVersion = FrameworkVersion.Unknown;
            if (module.IsMain)
            {
                FrameworkName frameworkName;
                if (TryGetFramework4Name(module.Assembly, out frameworkName))
                {
                    string frameworkVersionAsString = frameworkName.Version.ToString();
                    switch (frameworkVersionAsString)
                    {
                    case "4.0":
                        frameworkVersion = FrameworkVersion.v4_0;
                        break;

                    case "4.5":
                        frameworkVersion = FrameworkVersion.v4_5;
                        break;

                    case "4.5.1":
                        frameworkVersion = FrameworkVersion.v4_5_1;
                        break;

                    case "4.5.2":
                        frameworkVersion = FrameworkVersion.v4_5_2;
                        break;

                    case "4.6":
                        frameworkVersion = FrameworkVersion.v4_6;
                        break;

                    case "4.6.1":
                        frameworkVersion = FrameworkVersion.v4_6_1;
                        break;

                    default:
                        throw new FormatException();
                    }

                    return(true);
                }
                else
                {
                    bool isInFrameworkDir;
                    if (IsFramework4Assembly(module.Assembly, out isInFrameworkDir))
                    {
                        if (isInFrameworkDir)
                        {
                            frameworkVersion = Framework4VersionResolver.GetInstalledFramework4Version();
                        }
                        else
                        {
                            frameworkVersion = Framework4VersionResolver.GetFrameworkVersionByFileVersion(module.Assembly.MainModule.FilePath);
                        }

                        if (frameworkVersion != FrameworkVersion.Unknown)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }