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; Version fwkVersion; 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 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 && newFwkKind == 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, out fwkVersion); fwkInfo.FrameworkVersion = fwkVersion; if (fwkInfo.FrameworkKind == FrameworkKind.Unknown) { fwkInfo.FrameworkKind = GetFrameworkKind_TargetFrameworkAttribute(module, out var frameworkName, out fwkVersion); fwkInfo.FrameworkVersion = fwkVersion; if (fwkInfo.FrameworkKind == FrameworkKind.Unknown) { fwkInfo.FrameworkKind = GetFrameworkKind_AssemblyRefs(module, frameworkName, out fwkVersion); fwkInfo.FrameworkVersion = fwkVersion; } } if (fwkInfo.FrameworkKind == FrameworkKind.Unknown) { fwkInfo.FrameworkVersion = null; } 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); }