示例#1
0
        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;

            var cachedListFile = fxCacheDir.Combine(cacheKey + ".xml");
            var cachedListInfo = new FileInfo(cachedListFile);

            if (cachedListInfo.Exists && cachedListInfo.LastWriteTime == fxListInfo.LastWriteTime)
            {
                fxInfo = FrameworkInfo.Load(moniker, cachedListFile);
            }
            else
            {
                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
            });
        }
示例#2
0
        public static FrameworkInfo Load(TargetFrameworkMoniker moniker, FilePath frameworkListFile)
        {
            var info = new FrameworkInfo {
                Id = moniker
            };

            //for non-cached files, this file is in the RedistList subdir of the assembly dir
            info.TargetFrameworkDirectory = frameworkListFile.ParentDirectory.ParentDirectory;

            using (var reader = XmlReader.Create(frameworkListFile)) {
                if (!reader.ReadToDescendant("FileList"))
                {
                    throw new Exception("Missing FileList element");
                }

                if (reader.MoveToAttribute("Name") && reader.ReadAttributeValue())
                {
                    info.Name = reader.ReadContentAsString();
                }

                if (reader.MoveToAttribute("IncludeFramework") && reader.ReadAttributeValue())
                {
                    string include = reader.ReadContentAsString();
                    if (!string.IsNullOrEmpty(include))
                    {
                        info.IncludeFramework = include;
                    }
                }

                //this is a Mono-specific extension
                if (reader.MoveToAttribute("TargetFrameworkDirectory") && reader.ReadAttributeValue())
                {
                    string targetDir = reader.ReadContentAsString();
                    if (!string.IsNullOrEmpty(targetDir))
                    {
                        targetDir = targetDir.Replace('\\', Path.DirectorySeparatorChar);
                        info.TargetFrameworkDirectory = frameworkListFile.ParentDirectory.Combine(targetDir).FullPath;
                    }
                }

                info.Assemblies          = new List <AssemblyInfo> ();
                info.SupportedFrameworks = new List <SupportedFramework> ();

                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.LocalName)
                        {
                        case "File":
                            info.Assemblies.Add(ReadFileElement(reader));
                            break;

                        case "SupportedFramework":
                            info.SupportedFrameworks.Add(SupportedFramework.LoadFromAttributes(reader));
                            break;
                        }
                    }
                }
            }
            return(info);
        }
示例#3
0
        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
            });
        }