Esempio n. 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
            });
        }
Esempio n. 2
0
        public static TargetFramework FromFrameworkDirectory(TargetFrameworkMoniker moniker, FilePath dir)
        {
            var fxList = dir.Combine("RedistList", "FrameworkList.xml");

            if (!File.Exists(fxList))
            {
                return(null);
            }

            var fx = new TargetFramework(moniker);

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

                //not sure what this is for
                //if (reader.MoveToAttribute ("Redist") && reader.ReadAttributeValue ())
                //	redist = reader.ReadContentAsString ();

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

                if (reader.MoveToAttribute("RuntimeVersion") && reader.ReadAttributeValue())
                {
                    string runtimeVersion = reader.ReadContentAsString();
                    switch (runtimeVersion)
                    {
                    case "2.0":
                        fx.clrVersion = ClrVersion.Net_2_0;
                        break;

                    case "4.0":
                        fx.clrVersion = ClrVersion.Net_4_0;
                        break;

                    case "4.5":
                    case "4.5.1":
                        fx.clrVersion = ClrVersion.Net_4_5;
                        break;

                    default:
                        LoggingService.LogInfo("Framework {0} has unknown RuntimeVersion {1}", moniker, runtimeVersion);
                        return(null);
                    }
                }

                if (reader.MoveToAttribute("ToolsVersion") && reader.ReadAttributeValue())
                {
                    string toolsVersion = reader.ReadContentAsString();
                    switch (toolsVersion)
                    {
                    case "2.0":
                        fx.toolsVersion = TargetFrameworkToolsVersion.V2_0;
                        break;

                    case "3.5":
                        fx.toolsVersion = TargetFrameworkToolsVersion.V3_5;
                        break;

                    case "4.0":
                        fx.toolsVersion = TargetFrameworkToolsVersion.V4_0;
                        break;

                    case "4.5":
                        fx.toolsVersion = TargetFrameworkToolsVersion.V4_5;
                        break;

                    default:
                        LoggingService.LogInfo("Framework {0} has unknown ToolsVersion {1}", moniker, toolsVersion);
                        return(null);
                    }
                }

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

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

                var assemblies = new List <AssemblyInfo> ();
                if (reader.ReadToFollowing("File"))
                {
                    do
                    {
                        var ainfo = new AssemblyInfo();
                        assemblies.Add(ainfo);
                        if (reader.MoveToAttribute("AssemblyName") && reader.ReadAttributeValue())
                        {
                            ainfo.Name = reader.ReadContentAsString();
                        }
                        if (string.IsNullOrEmpty(ainfo.Name))
                        {
                            throw new Exception("Missing AssemblyName attribute");
                        }
                        if (reader.MoveToAttribute("Version") && reader.ReadAttributeValue())
                        {
                            ainfo.Version = reader.ReadContentAsString();
                        }
                        if (reader.MoveToAttribute("PublicKeyToken") && reader.ReadAttributeValue())
                        {
                            ainfo.PublicKeyToken = reader.ReadContentAsString();
                        }
                        if (reader.MoveToAttribute("Culture") && reader.ReadAttributeValue())
                        {
                            ainfo.Culture = reader.ReadContentAsString();
                        }
                        if (reader.MoveToAttribute("ProcessorArchitecture") && reader.ReadAttributeValue())
                        {
                            ainfo.ProcessorArchitecture = (ProcessorArchitecture)
                                                          Enum.Parse(typeof(ProcessorArchitecture), reader.ReadContentAsString(), true);
                        }
                        if (reader.MoveToAttribute("InGac") && reader.ReadAttributeValue())
                        {
                            ainfo.InGac = reader.ReadContentAsBoolean();
                        }
                    } while (reader.ReadToFollowing("File"));
                }
                else
                {
                    // HACK: we were using EnumerateFiles but it's broken in some Mono releases
                    // https://bugzilla.xamarin.com/show_bug.cgi?id=2975
                    var files = Directory.GetFiles(dir, "*.dll");
                    foreach (var f in files)
                    {
                        try {
                            var an    = SystemAssemblyService.GetAssemblyNameObj(dir.Combine(f));
                            var ainfo = new AssemblyInfo();
                            ainfo.Update(an);
                            assemblies.Add(ainfo);
                        } catch (Exception ex) {
                            LoggingService.LogError("Error reading name for assembly '{0}' in framework '{1}':\n{2}",
                                                    f, fx.Id, ex.ToString());
                        }
                    }
                }

                fx.Assemblies = assemblies.ToArray();
            }

            var supportedFrameworksDir = dir.Combine("SupportedFrameworks");

            if (Directory.Exists(supportedFrameworksDir))
            {
                foreach (var sfx in Directory.GetFiles(supportedFrameworksDir))
                {
                    fx.SupportedFrameworks.Add(SupportedFramework.Load(fx, sfx));
                }
            }

            return(fx);
        }
Esempio n. 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
            });
        }
Esempio n. 4
0
        public static TargetFramework FromFrameworkDirectory(TargetFrameworkMoniker moniker, FilePath dir)
        {
            var fxList = dir.Combine("RedistList", "FrameworkList.xml");

            if (!File.Exists(fxList))
            {
                return(null);
            }

            var fx = new TargetFramework(moniker);

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

                //not sure what this is for
                //if (reader.MoveToAttribute ("Redist") && reader.ReadAttributeValue ())
                //	redist = reader.ReadContentAsString ();

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

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

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

                var assemblies = new List <AssemblyInfo> ();
                if (reader.ReadToFollowing("File"))
                {
                    do
                    {
                        var ainfo = new AssemblyInfo();
                        assemblies.Add(ainfo);
                        if (reader.MoveToAttribute("AssemblyName") && reader.ReadAttributeValue())
                        {
                            ainfo.Name = reader.ReadContentAsString();
                        }
                        if (string.IsNullOrEmpty(ainfo.Name))
                        {
                            throw new Exception("Missing AssemblyName attribute");
                        }
                        if (reader.MoveToAttribute("Version") && reader.ReadAttributeValue())
                        {
                            ainfo.Version = reader.ReadContentAsString();
                        }
                        if (reader.MoveToAttribute("PublicKeyToken") && reader.ReadAttributeValue())
                        {
                            ainfo.PublicKeyToken = reader.ReadContentAsString();
                        }
                        if (reader.MoveToAttribute("Culture") && reader.ReadAttributeValue())
                        {
                            ainfo.Culture = reader.ReadContentAsString();
                        }
                        if (reader.MoveToAttribute("ProcessorArchitecture") && reader.ReadAttributeValue())
                        {
                            ainfo.ProcessorArchitecture = (ProcessorArchitecture)
                                                          Enum.Parse(typeof(ProcessorArchitecture), reader.ReadContentAsString(), true);
                        }
                        if (reader.MoveToAttribute("InGac") && reader.ReadAttributeValue())
                        {
                            ainfo.InGac = reader.ReadContentAsBoolean();
                        }
                    } while (reader.ReadToFollowing("File"));
                }
                else if (Directory.Exists(dir))
                {
                    foreach (var f in Directory.EnumerateFiles(dir, "*.dll"))
                    {
                        try {
                            var an    = SystemAssemblyService.GetAssemblyNameObj(dir.Combine(f));
                            var ainfo = new AssemblyInfo();
                            ainfo.Update(an);
                            assemblies.Add(ainfo);
                        } catch (BadImageFormatException ex) {
                            LoggingService.LogError("Invalid assembly in framework '{0}': {1}{2}{3}", fx.Id, f, Environment.NewLine, ex.ToString());
                        } catch (Exception ex) {
                            LoggingService.LogError("Error reading assembly '{0}' in framework '{1}':{2}{3}",
                                                    f, fx.Id, Environment.NewLine, ex.ToString());
                        }
                    }
                }

                fx.Assemblies = assemblies.ToArray();
            }

            var supportedFrameworksDir = dir.Combine("SupportedFrameworks");

            if (Directory.Exists(supportedFrameworksDir))
            {
                foreach (var sfx in Directory.GetFiles(supportedFrameworksDir))
                {
                    fx.SupportedFrameworks.Add(SupportedFramework.Load(fx, sfx));
                }
            }

            return(fx);
        }