Esempio n. 1
0
		FrameworkKind GetRuntimeFrameworkKind(string filename, out Version netCoreVersion) {
			foreach (var gacPath in GacInfo.GacPaths) {
				if (FileUtils.IsFileInDir(gacPath.Path, filename)) {
					netCoreVersion = null;
					Debug.Assert(gacPath.Version == GacVersion.V2 || gacPath.Version == GacVersion.V4);
					return gacPath.Version == GacVersion.V2 ? FrameworkKind.DotNetFramework2 : FrameworkKind.DotNetFramework4;
				}
			}

			netCoreVersion = dotNetCorePathProvider.TryGetDotNetCoreVersion(filename);
			if (netCoreVersion != null)
				return FrameworkKind.DotNetCore;

			netCoreVersion = null;
			return FrameworkKind.Unknown;
		}
Esempio n. 2
0
        FrameworkKind GetFrameworkKind(ModuleDef module, out Version netCoreVersion, out string sourceModuleDirectoryHint)
        {
            if (module == null)
            {
                netCoreVersion            = null;
                sourceModuleDirectoryHint = null;
                return(FrameworkKind.Unknown);
            }

            var sourceFilename = module.Location;

            if (!string.IsNullOrEmpty(sourceFilename))
            {
                bool isExe = (module.Characteristics & Characteristics.Dll) == 0;
                foreach (var info in frameworkInfos)
                {
                    if (FileUtils.IsFileInDir(info.Directory, sourceFilename))
                    {
                        // The same 'module' could be passed in here multiple times, but we can't save the module instance
                        // anywhere so only update info if it's an EXE and then mark it as frozen.
                        if (isExe && !info.Frozen)
                        {
                            info.Frozen = true;
                            var newFwkKind = GetFrameworkKind_TargetFrameworkAttribute(module, out var frameworkName, out var fwkVersion);
                            if (newFwkKind == FrameworkKind.Unknown)
                            {
                                newFwkKind = GetFrameworkKind_AssemblyRefs(module, frameworkName, out fwkVersion);
                            }
                            if (newFwkKind != FrameworkKind.Unknown)
                            {
                                info.FrameworkKind = Best(info.FrameworkKind, newFwkKind);
                                if (info.FrameworkKind == FrameworkKind.DotNetCore)
                                {
                                    info.FrameworkVersion = fwkVersion;
                                }
                            }
                        }
                        if (info.FrameworkKind == FrameworkKind.DotNetCore)
                        {
                            netCoreVersion = info.FrameworkVersion;
                        }
                        else
                        {
                            netCoreVersion = null;
                        }
                        sourceModuleDirectoryHint = info.Directory;
                        return(info.FrameworkKind);
                    }
                }

                var fwkKind = GetRuntimeFrameworkKind(sourceFilename, out var frameworkVersion);
                if (fwkKind != FrameworkKind.Unknown)
                {
                    if (fwkKind == FrameworkKind.DotNetCore)
                    {
                        netCoreVersion = frameworkVersion;
                    }
                    else
                    {
                        netCoreVersion = null;
                    }
                    sourceModuleDirectoryHint = null;
                    return(fwkKind);
                }

                var fwkInfo = new FrameworkPathInfo(Path.GetDirectoryName(sourceFilename));
                fwkInfo.FrameworkKind = GetFrameworkKind_Directory(fwkInfo.Directory);
                if (fwkInfo.FrameworkKind == FrameworkKind.Unknown)
                {
                    fwkInfo.FrameworkKind    = GetFrameworkKind_TargetFrameworkAttribute(module, out var frameworkName, out var fwkVersion);
                    fwkInfo.FrameworkVersion = fwkVersion;
                    if (fwkInfo.FrameworkKind == FrameworkKind.Unknown)
                    {
                        fwkInfo.FrameworkKind    = GetFrameworkKind_AssemblyRefs(module, frameworkName, out fwkVersion);
                        fwkInfo.FrameworkVersion = fwkVersion;
                    }
                }
                fwkInfo.Frozen = isExe;
                fwkInfo        = Add(fwkInfo);
                if (fwkInfo.FrameworkKind == FrameworkKind.DotNetCore)
                {
                    netCoreVersion = fwkInfo.FrameworkVersion;
                }
                else
                {
                    netCoreVersion = null;
                }
                sourceModuleDirectoryHint = fwkInfo.Directory;
                return(fwkInfo.FrameworkKind);
            }

            netCoreVersion            = null;
            sourceModuleDirectoryHint = null;
            return(FrameworkKind.Unknown);
        }