// Given the full name of an assembly, returns the corresponding full assembly name
        // in the specified target CLR version, or null if it doesn't exist in that version.
        public SystemAssembly GetAssemblyForVersion(string fullName, string packageName, TargetFramework fx)
        {
            Initialize();

            fullName = NormalizeAsmName(fullName);

            //get the SystemAssembly for the current fullname, NOT the new target fx
            //in order to be able to check whether it's a framework assembly
            SystemAssembly asm = GetAssemblyFromFullName(fullName, packageName, null);

            if (asm == null)
            {
                return(null);
            }

            var fxAsms = asm.AllSameName().Where(a => a.Package.IsFrameworkPackage);

            //if the asm is not a framework asm, we don't upgrade it automatically
            if (!fxAsms.Any())
            {
                // Return null if the package is not compatible with the requested version
                if (fx.CanReferenceAssembliesTargetingFramework(asm.Package.TargetFramework))
                {
                    return(asm);
                }
                else
                {
                    return(null);
                }
            }

            foreach (var fxAsm in fxAsms)
            {
                if (fx.IncludesFramework(fxAsm.Package.TargetFramework))
                {
                    return(fxAsm);
                }
            }

            // We have to find the assembly with the same name in the target fx
            string fname = Path.GetFileName((string)fxAsms.First().Location);

            foreach (var pair in assemblyFullNameToAsm)
            {
                foreach (var fxAsm in pair.Value.AllSameName())
                {
                    var rpack = fxAsm.Package;
                    if (rpack.IsFrameworkPackage && fx.IncludesFramework(rpack.TargetFramework) && Path.GetFileName(fxAsm.Location) == fname)
                    {
                        return(fxAsm);
                    }
                }
            }
            return(null);
        }
        public SystemAssembly GetAssemblyFromFullName(string fullname, string package, TargetFramework fx)
        {
            if (package == null)
            {
                SystemAssembly found    = null;
                SystemAssembly gacFound = null;
                foreach (SystemAssembly asm in GetAssembliesFromFullNameInternal(fullname))
                {
                    found = asm;
                    if (asm.Package.IsFrameworkPackage && fx != null && fx.IncludesFramework(asm.Package.TargetFramework))
                    {
                        return(asm);
                    }
                    if (asm.Package.IsGacPackage)
                    {
                        gacFound = asm;
                    }
                }
                return(gacFound ?? found);
            }

            foreach (SystemAssembly asm in GetAssembliesFromFullNameInternal(fullname))
            {
                if (package == asm.Package.Name)
                {
                    return(asm);
                }
            }
            return(null);
        }
        // Returns the installed version of the given assembly name
        // (it returns the full name of the installed assembly).
        public string FindInstalledAssembly(string fullname, string package, TargetFramework fx)
        {
            Initialize();
            fullname = NormalizeAsmName(fullname);

            SystemAssembly fasm = GetAssemblyFromFullName(fullname, package, fx);

            if (fasm != null)
            {
                return(fullname);
            }

            // Try to find a newer version of the same assembly, preferring framework assemblies
            if (fx == null)
            {
                string best = null;
                foreach (SystemAssembly asm in FindNewerAssembliesSameName(fullname))
                {
                    if (package == null || asm.Package.Name == package)
                    {
                        if (asm.Package.IsFrameworkPackage)
                        {
                            return(asm.FullName);
                        }
                        else
                        {
                            best = asm.FullName;
                        }
                    }
                }
                return(best);
            }

            string bestMatch = null;

            foreach (SystemAssembly asm in FindNewerAssembliesSameName(fullname))
            {
                if (asm.Package.IsFrameworkPackage)
                {
                    if (fx.IncludesFramework(asm.Package.TargetFramework))
                    {
                        if (package == null || asm.Package.Name == package)
                        {
                            return(asm.FullName);
                        }
                    }
                }
                else if (fx.CanReferenceAssembliesTargetingFramework(asm.Package.TargetFramework))
                {
                    if (package != null && asm.Package.Name == package)
                    {
                        return(asm.FullName);
                    }
                    bestMatch = asm.FullName;
                }
            }
            return(bestMatch);
        }
Example #4
0
        // Given the full name of an assembly, returns the corresponding full assembly name
        // in the specified target CLR version, or null if it doesn't exist in that version.
        public SystemAssembly GetAssemblyForVersion(string fullName, string packageName, TargetFramework fx)
        {
            Initialize();

            fullName = NormalizeAsmName(fullName);

            //get the SystemAssembly for the current fullname, NOT the new target fx
            //in order to be able to check whether it's a framework assembly
            SystemAssembly asm = GetAssemblyFromFullName(fullName, packageName, null);

            if (asm == null)
            {
                return(null);
            }

            var fxAsms = asm.AllSameName().Where(a => a.Package.IsFrameworkPackage).ToList();

            //if the asm is not a framework asm, we don't upgrade it automatically
            if (!fxAsms.Any())
            {
                // Return null if the package is not compatible with the requested version
                if (fx.CanReferenceAssembliesTargetingFramework(asm.Package.TargetFramework))
                {
                    return(asm);
                }
                else
                {
                    return(null);
                }
            }

            var bestFx = BestFrameworkAssembly(fxAsms, fx);

            if (bestFx != null)
            {
                return(bestFx);
            }

            // We have to find the assembly with the same name in the target fx
            string fname = Path.GetFileName(fxAsms.First().Location);

            var possible = packages.Where(p => p.IsFrameworkPackage && fx.IncludesFramework(p.TargetFramework))
                           .SelectMany(p => p.Assemblies)
                           .Where(a => Path.GetFileName(a.Location) == fname)
                           .ToList();

            return(BestFrameworkAssembly(possible));
        }
Example #5
0
 IEnumerable <SystemPackage> GetPackagesInternal(TargetFramework fx)
 {
     foreach (SystemPackage pkg in packages)
     {
         if (pkg.IsFrameworkPackage)
         {
             if (fx.IncludesFramework(pkg.TargetFramework))
             {
                 yield return(pkg);
             }
         }
         else
         {
             if (fx.CanReferenceAssembliesTargetingFramework(pkg.TargetFramework))
             {
                 yield return(pkg);
             }
         }
     }
 }
Example #6
0
 public IEnumerable <SystemPackage> GetPackages(TargetFramework fx)
 {
     foreach (SystemPackage pkg in packages)
     {
         if (pkg.IsFrameworkPackage)
         {
             if (fx.IncludesFramework(pkg.TargetFramework))
             {
                 yield return(pkg);
             }
         }
         else
         {
             if (fx.IsCompatibleWithFramework(pkg.TargetFramework))
             {
                 yield return(pkg);
             }
         }
     }
 }
Example #7
0
 static SystemAssembly BestFrameworkAssembly(IEnumerable <SystemAssembly> assemblies, TargetFramework fx)
 {
     if (fx == null)
     {
         return(null);
     }
     return(BestFrameworkAssembly(
                assemblies
                .Where(a => a.Package != null && a.Package.IsFrameworkPackage && fx.IncludesFramework(a.Package.TargetFramework))
                .ToList()
                ));
 }
		// Given the full name of an assembly, returns the corresponding full assembly name
		// in the specified target CLR version, or null if it doesn't exist in that version.
		public SystemAssembly GetAssemblyForVersion (string fullName, string packageName, TargetFramework fx)
		{
			Initialize ();

			fullName = NormalizeAsmName (fullName);
			
			//get the SystemAssembly for the current fullname, NOT the new target fx
			//in order to be able to check whether it's a framework assembly
			SystemAssembly asm = GetAssemblyFromFullName (fullName, packageName, null);

			if (asm == null)
				return null;
			
			var fxAsms = asm.AllSameName ().Where (a => a.Package.IsFrameworkPackage).ToList ();
			
			//if the asm is not a framework asm, we don't upgrade it automatically
			if (!fxAsms.Any ()) {
				// Return null if the package is not compatible with the requested version
				if (fx.CanReferenceAssembliesTargetingFramework (asm.Package.TargetFramework))
					return asm;
				else
					return null;
			}
			
			var bestFx = BestFrameworkAssembly (fxAsms, fx);
			if (bestFx != null)
				return bestFx;

			// We have to find the assembly with the same name in the target fx
			string fname = Path.GetFileName (fxAsms.First ().Location);

			var possible = packages.Where (p => p.IsFrameworkPackage && fx.IncludesFramework (p.TargetFramework))
				.SelectMany (p => p.Assemblies)
				.Where (a => Path.GetFileName (a.Location) == fname)
				.ToList ();

			return BestFrameworkAssembly (possible);
		}
		static SystemAssembly BestFrameworkAssembly (IEnumerable<SystemAssembly> assemblies, TargetFramework fx)
		{
			if (fx == null)
				return null;
			return BestFrameworkAssembly (
				assemblies
				.Where (a => a.Package != null && a.Package.IsFrameworkPackage && fx.IncludesFramework (a.Package.TargetFramework))
				.ToList ()
			);
		}
Example #10
0
		IEnumerable<SystemPackage> GetPackagesInternal (TargetFramework fx)
		{
			foreach (SystemPackage pkg in packages) {
				if (pkg.IsFrameworkPackage) {
					if (fx.IncludesFramework (pkg.TargetFramework))
						yield return pkg;
				} else {
					if (fx.CanReferenceAssembliesTargetingFramework (pkg.TargetFramework))
						yield return pkg;
				}		
			}
		}
		// Given the full name of an assembly, returns the corresponding full assembly name
		// in the specified target CLR version, or null if it doesn't exist in that version.
		public SystemAssembly GetAssemblyForVersion (string fullName, string packageName, TargetFramework fx)
		{
			Initialize ();

			fullName = NormalizeAsmName (fullName);
			
			//get the SystemAssembly for the current fullname, NOT the new target fx
			//in order to be able to check whether it's a framework assembly
			SystemAssembly asm = GetAssemblyFromFullName (fullName, packageName, null);

			if (asm == null)
				return null;
			
			var fxAsms = asm.AllSameName ().Where (a => a.Package.IsFrameworkPackage);
			
			//if the asm is not a framework asm, we don't upgrade it automatically
			if (!fxAsms.Any ()) {
				// Return null if the package is not compatible with the requested version
				if (fx.CanReferenceAssembliesTargetingFramework (asm.Package.TargetFramework))
					return asm;
				else
					return null;
			}
			
			foreach (var fxAsm in fxAsms) {
				if (fx.IncludesFramework (fxAsm.Package.TargetFramework))
					return fxAsm;
			}

			// We have to find the assembly with the same name in the target fx
			string fname = Path.GetFileName ((string) fxAsms.First ().Location);
			
			foreach (var pair in assemblyFullNameToAsm) {
				foreach (var fxAsm in pair.Value.AllSameName ()) {
					var rpack = fxAsm.Package;
					if (rpack.IsFrameworkPackage && fx.IncludesFramework (rpack.TargetFramework) && Path.GetFileName (fxAsm.Location) == fname)
						return fxAsm;
				}
			}
			return null;
		}
		// Returns the installed version of the given assembly name
		// (it returns the full name of the installed assembly).
		public string FindInstalledAssembly (string fullname, string package, TargetFramework fx)
		{
			Initialize ();
			fullname = NormalizeAsmName (fullname);
			
			SystemAssembly fasm = GetAssemblyFromFullName (fullname, package, fx);
			if (fasm != null)
				return fullname;
			
			// Try to find a newer version of the same assembly, preferring framework assemblies
			if (fx == null) {
				string best = null;
				foreach (SystemAssembly asm in FindNewerAssembliesSameName (fullname)) {
					if (package == null || asm.Package.Name == package) {
						if (asm.Package.IsFrameworkPackage)
							return asm.FullName;
						else
							best = asm.FullName;
					}
				}
				return best;
			}
			
			string bestMatch = null;
			foreach (SystemAssembly asm in FindNewerAssembliesSameName (fullname)) {
				if (asm.Package.IsFrameworkPackage) {
					if (fx.IncludesFramework (asm.Package.TargetFramework))
						if (package == null || asm.Package.Name == package)
							return asm.FullName;
				} else if (fx.CanReferenceAssembliesTargetingFramework (asm.Package.TargetFramework)) {
					if (package != null && asm.Package.Name == package)
						return asm.FullName;
					bestMatch = asm.FullName;
				}
			}
			return bestMatch;
		}
		public SystemAssembly GetAssemblyFromFullName (string fullname, string package, TargetFramework fx)
		{
			if (package == null) {
				SystemAssembly found = null;
				SystemAssembly gacFound = null;
				foreach (SystemAssembly asm in GetAssembliesFromFullNameInternal (fullname)) {
					found = asm;
					if (asm.Package.IsFrameworkPackage && fx != null && fx.IncludesFramework (asm.Package.TargetFramework))
						return asm;
					if (asm.Package.IsGacPackage)
						gacFound = asm;
				}
				return gacFound ?? found;
			}
			
			foreach (SystemAssembly asm in GetAssembliesFromFullNameInternal (fullname)) {
				if (package == asm.Package.Name)
					return asm;
			}
			return null;
		}
Example #14
0
		public IEnumerable<SystemPackage> GetPackages (TargetFramework fx)
		{
			foreach (SystemPackage pkg in packages) {
				if (pkg.IsFrameworkPackage) {
					if (fx.IncludesFramework (pkg.TargetFramework))
						yield return pkg;
				} else {
					if (fx.IsCompatibleWithFramework (pkg.TargetFramework))
						yield return pkg;
				}		
			}
		}