// 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.IsCompatibleWithFramework(asm.Package.TargetFramework))
                {
                    return(asm);
                }
                else
                {
                    return(null);
                }
            }

            foreach (var fxAsm in fxAsms)
            {
                if (fx.IsExtensionOfFramework(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.IsExtensionOfFramework(rpack.TargetFramework) && Path.GetFileName(fxAsm.Location) == fname)
                    {
                        return(fxAsm);
                    }
                }
            }
            return(null);
        }
Beispiel #2
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));
        }