public static TargetFramework FromFrameworkDirectory(TargetFrameworkMoniker moniker, FilePath dir) { var fxListFile = dir.Combine("RedistList", "FrameworkList.xml"); var fxListInfo = new FileInfo(fxListFile); if (!fxListInfo.Exists) { return(null); } var fxCacheDir = UserProfile.Current.CacheDir.Combine("FrameworkInfo"); var cacheKey = moniker.Identifier + "_" + moniker.Version; if (!string.IsNullOrEmpty(moniker.Profile)) { cacheKey += "_" + moniker.Profile; } FrameworkInfo fxInfo = null; var cachedListFile = fxCacheDir.Combine(cacheKey + ".xml"); var cachedListInfo = new FileInfo(cachedListFile); if (cachedListInfo.Exists && cachedListInfo.LastWriteTime == fxListInfo.LastWriteTime) { fxInfo = FrameworkInfo.Load(moniker, cachedListFile); //if Mono was upgraded since caching, the cached location may no longer be valid if (!Directory.Exists(fxInfo.TargetFrameworkDirectory)) { fxInfo = null; } else if (fxInfo.SupportedFrameworks.Count > 0) { // Ensure DisplayName was saved for the SupportedFrameworks. If missing invalidate the // cache to ensure DisplayName is saved. Only check the first framework since the // DisplayName was not being saved previously. The DisplayName will not be empty when // saved even if the framework .xml file does not define it since the filename will be // used as the DisplayName in that case. if (string.IsNullOrEmpty(fxInfo.SupportedFrameworks [0].DisplayName)) { fxInfo = null; } } } if (fxInfo == null) { fxInfo = FrameworkInfo.Load(moniker, fxListFile); var supportedFrameworksDir = dir.Combine("SupportedFrameworks"); if (Directory.Exists(supportedFrameworksDir)) { foreach (var sfx in Directory.EnumerateFiles(supportedFrameworksDir)) { fxInfo.SupportedFrameworks.Add(SupportedFramework.Load(sfx)); } } if (fxInfo.Assemblies.Count == 0) { fxInfo.Assemblies = ScanAssemblyDirectory(moniker, fxInfo.TargetFrameworkDirectory); } Directory.CreateDirectory(fxCacheDir); fxInfo.Save(cachedListFile); File.SetLastWriteTime(cachedListFile, fxListInfo.LastWriteTime); } return(new TargetFramework(moniker) { name = fxInfo.Name, includesFramework = fxInfo.IncludeFramework, Assemblies = fxInfo.Assemblies.ToArray(), supportedFrameworks = fxInfo.SupportedFrameworks, FrameworkAssembliesDirectory = fxInfo.TargetFrameworkDirectory }); }
public static TargetFramework FromFrameworkDirectory(TargetFrameworkMoniker moniker, FilePath dir) { var fxListFile = dir.Combine("RedistList", "FrameworkList.xml"); var fxListInfo = new FileInfo(fxListFile); if (!fxListInfo.Exists) { return(null); } var fxCacheDir = UserProfile.Current.CacheDir.Combine("FrameworkInfo"); var cacheKey = moniker.Identifier + "_" + moniker.Version; if (!string.IsNullOrEmpty(moniker.Profile)) { cacheKey += "_" + moniker.Profile; } FrameworkInfo fxInfo = null; var cachedListFile = fxCacheDir.Combine(cacheKey + ".xml"); var cachedListInfo = new FileInfo(cachedListFile); if (cachedListInfo.Exists && cachedListInfo.LastWriteTime == fxListInfo.LastWriteTime) { fxInfo = FrameworkInfo.Load(moniker, cachedListFile); //if Mono was upgraded since caching, the cached location may no longer be valid if (!Directory.Exists(fxInfo.TargetFrameworkDirectory)) { fxInfo = null; } } if (fxInfo == null) { fxInfo = FrameworkInfo.Load(moniker, fxListFile); var supportedFrameworksDir = dir.Combine("SupportedFrameworks"); if (Directory.Exists(supportedFrameworksDir)) { foreach (var sfx in Directory.EnumerateFiles(supportedFrameworksDir)) { fxInfo.SupportedFrameworks.Add(SupportedFramework.Load(sfx)); } } if (fxInfo.Assemblies.Count == 0) { fxInfo.Assemblies = ScanAssemblyDirectory(moniker, fxInfo.TargetFrameworkDirectory); } Directory.CreateDirectory(fxCacheDir); fxInfo.Save(cachedListFile); File.SetLastWriteTime(cachedListFile, fxListInfo.LastWriteTime); } return(new TargetFramework(moniker) { name = fxInfo.Name, includesFramework = fxInfo.IncludeFramework, Assemblies = fxInfo.Assemblies.ToArray(), supportedFrameworks = fxInfo.SupportedFrameworks, FrameworkAssembliesDirectory = fxInfo.TargetFrameworkDirectory }); }