Example #1
0
		internal static SystemAssembly FromFile (string file, AssemblyInfo ainfo)
		{
			if (ainfo == null || ainfo.Version == null)
				return FromFile (file);
			string token = (string.IsNullOrEmpty (ainfo.PublicKeyToken) || ainfo.PublicKeyToken == "null")?
				String.Empty : ", PublicKeyToken=" + ainfo.PublicKeyToken;
			string fn = ainfo.Name + ", Version=" + ainfo.Version +", Culture=neutral" + token;
			return new SystemAssembly (file, fn);
		}
Example #2
0
		internal TargetFramework (TargetFrameworkMoniker id)
		{
			this.id = id;
			this.name = id.Profile == null
				? string.Format ("{0} {1}", id.Identifier, id.Version)
				: string.Format ("{0} {1} {2} Profile", id.Identifier, id.Version, id.Profile);
			clrVersion = ClrVersion.Default;
			Assemblies = new AssemblyInfo[0];
		}
		internal TargetFramework (string id)
		{
			Index = FrameworkCount++;
			this.id = id;
			this.name = id;
			clrVersion = ClrVersion.Default;
			Assemblies = new AssemblyInfo[0];
			compatibleFrameworks.Add (id);
			extendedFrameworks.Add (id);
		}
		internal SystemAssembly AddAssembly (string assemblyfile, AssemblyInfo ainfo, SystemPackage package)
		{
			if (!File.Exists (assemblyfile))
				return null;

			try {
				SystemAssembly asm = SystemAssembly.FromFile (assemblyfile, ainfo);
				SystemAssembly prevAsm;
				if (assemblyFullNameToAsm.TryGetValue (asm.FullName, out prevAsm)) {
					asm.NextSameName = prevAsm.NextSameName;
					prevAsm.NextSameName = asm;
				} else
					assemblyFullNameToAsm [asm.FullName] = asm;
				assemblyPathToPackage [assemblyfile] = package;
				return asm;
			} catch {
				return null;
			}
		}
Example #5
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;
					//The concept of "ClrVersion" breaks down hard after 4.5 and is essentially meaningless
					default:
						fx.clrVersion = ClrVersion.Net_4_5;
						break;
					}
				}
				
				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 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;
		}
Example #6
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.IncludedFrameworks.Add (new TargetFrameworkMoniker (fx.Id.Identifier, 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 = System.IO.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;
		}
		public static TargetFramework FromFrameworkDirectory (TargetFrameworkMoniker moniker, FilePath dir)
		{
			var fxList = dir.Combine ("RedistList", "FrameworkList.xml");
			if (!System.IO.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;
					default:
						throw new Exception ("Unknown RuntimeVersion '" + runtimeVersion + "'");
					}
				}
				
				if (reader.MoveToAttribute ("ToolsVersion") && reader.ReadAttributeValue ()) {
					string runtimeVersion = reader.ReadContentAsString ();
					switch (runtimeVersion) {
					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;
					default:
						throw new Exception ("Unknown ToolsVersion '" + runtimeVersion + "'");
					}
				}
				
				if (reader.MoveToAttribute ("IncludeFramework") && reader.ReadAttributeValue ()) {
					string include = reader.ReadContentAsString ();
					if (!string.IsNullOrEmpty (include)) {
						fx.IncludedFrameworks.Add (new TargetFrameworkMoniker (fx.Id.Identifier, include));
					}
				}
				
				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 {
					var files = System.IO.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 ();
			}
			
			return fx;
		}
Example #8
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;

                    //The concept of "ClrVersion" breaks down hard after 4.5 and is essentially meaningless
                    default:
                        fx.clrVersion = ClrVersion.Net_4_5;
                        break;
                    }
                }

                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 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);
        }