예제 #1
0
        private bool isApplicableAssembly(
            Metaspec.AssemblyInfo assemblyInfo,
            ExternalAssemblyReferenceInfo csProjAssemblyReferenceInfo
            )
        {
            //system dll
            if (csProjAssemblyReferenceInfo.assemblyInfo.getVersion().isNull())
            {
                string requiredTargetFramework = csProjAssemblyReferenceInfo.solutionRequiredTargetFramework;
                if (requiredTargetFramework != null)
                {
                    AssemblyVersion av = getMinAssemblyVersionFromRequiredTargetFramework(requiredTargetFramework);

                    if (assemblyInfo.getVersion() > av)
                    {
                        return(false);
                    }
                }
            }

            if (csProjAssemblyReferenceInfo.specificVersion)
            {
                if (assemblyInfo.Version.MajorVersion != csProjAssemblyReferenceInfo.assemblyInfo.Version.MajorVersion ||
                    assemblyInfo.Version.MinorVersion != csProjAssemblyReferenceInfo.assemblyInfo.Version.MinorVersion ||
                    assemblyInfo.Version.BuildNumber != csProjAssemblyReferenceInfo.assemblyInfo.Version.BuildNumber ||
                    assemblyInfo.Version.RevisionNumber != csProjAssemblyReferenceInfo.assemblyInfo.Version.RevisionNumber)
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #2
0
 Metaspec.AssemblyInfo getAssemblyKey(IExternalAssembly assembly)
 {
     Metaspec.AssemblyInfo   key  = null;
     Metaspec.AssemblyInfo[] keys = assembly.getAssemblyKeys();
     if (keys != null &&
         keys.Length >= 1)
     {
         key = keys[0];
     }
     return(key);
 }
예제 #3
0
        IExternalAssembly betterAssembly(Metaspec.AssemblyInfo info, IExternalAssembly[] assemblies, bool any)
        {
            AssemblyVersion version = info.Version;
            bool            system  = false;

            if (info.Name == "mscorlib" ||
                info.Name == "System.Core")
            {
                version.MinorVersion   = 0;
                version.BuildNumber    = 0;
                version.RevisionNumber = 0;
                system = true;
            }

            bool bestFound = true;

            for (int i = 0; i != assemblies.Length; ++i)
            {
                bestFound = true;
                for (int j = 0; j != assemblies.Length; ++j)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    int better = 0;
                    Metaspec.AssemblyInfo ai = getAssemblyKey(assemblies[i]);
                    Metaspec.AssemblyInfo aj = getAssemblyKey(assemblies[j]);
                    if (ai != null &&
                        aj != null)
                    {
                        better = betterAssembly2(info.Version, ai.Version, aj.Version, system);
                    }
                    if (better != 1)
                    {
                        bestFound = false;
                        break;
                    }
                }
                if (bestFound)
                {
                    return(assemblies[i]);
                }
            }

            if (any)
            {
                return(assemblies[0]);
            }

            return(null);
        }
예제 #4
0
        int selectBetterAssembly(
            ExternalAssemblyReferenceInfo csProjAssemblyReferenceInfo,
            Metaspec.AssemblyInfo assemblyInfo1,
            Metaspec.AssemblyInfo assemblyInfo2
            )
        {
            bool ap1 = isApplicableAssembly(assemblyInfo1, csProjAssemblyReferenceInfo);
            bool ap2 = isApplicableAssembly(assemblyInfo2, csProjAssemblyReferenceInfo);

            if (ap1 != ap2)
            {
                if (ap1)
                {
                    return(1);
                }
                else
                {
                    return(2);
                }
            }

            bool            csProjAssemblyReferenceInfoAssemblyInfoIsNull = csProjAssemblyReferenceInfo.assemblyInfo.getVersion().isNull();
            string          requiredTargetFramework = csProjAssemblyReferenceInfo.solutionRequiredTargetFramework;
            AssemblyVersion av1 = assemblyInfo1.getVersion();
            AssemblyVersion av2 = assemblyInfo2.getVersion();

            //system dll
            if (csProjAssemblyReferenceInfoAssemblyInfoIsNull &&
                requiredTargetFramework != null)
            {
                AssemblyVersion av = getMinAssemblyVersionFromRequiredTargetFramework(requiredTargetFramework);
                bool            g1 = av1 >= av;
                bool            g2 = av2 >= av;
                if (g1 != g2)
                {
                    if (g1)
                    {
                        return(1);
                    }
                    else
                    {
                        return(2);
                    }
                }
            }

            //user dll
            else
            {
                AssemblyVersion av = csProjAssemblyReferenceInfo.assemblyInfo.getVersion();

                bool g1 = av1 >= av;
                bool g2 = av2 >= av;
                if (g1 != g2)
                {
                    if (g1)
                    {
                        return(1);
                    }
                    else
                    {
                        return(2);
                    }
                }
                if (g1 && g2)
                {
                    if (av1 > av2)
                    {
                        return(1);
                    }
                    else if (av2 > av1)
                    {
                        return(2);
                    }
                }
            }

            string processorArhitecture;

            if (csProjAssemblyReferenceInfo.assemblyInfo.ProcessorArchitecture != null)
            {
                processorArhitecture = csProjAssemblyReferenceInfo.assemblyInfo.ProcessorArchitecture;
            }
            else
            {
                processorArhitecture = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
            }
            if (assemblyInfo1.ProcessorArchitecture == processorArhitecture)
            {
                return(1);
            }
            else if (assemblyInfo2.ProcessorArchitecture == processorArhitecture)
            {
                return(2);
            }

            return(0);
        }
예제 #5
0
        //The rules Visual Studio uses to resolve references are as follows:
        //1. Assemblies that are visible in the project as project items or links are considered.
        //   If Visual Studio .NET 2005 with MSBuild is being used, these must have a Build Action of Content or None.
        //2. Assemblies in Reference Path directories are considered.
        //   These are stored in .user files and are visible under project properties.
        //3. The HintPath of the reference is considered.
        //   This is a path to the referenced assembly (relative to the project).
        //   It is stored when the reference is originally created.
        //4. Assemblies in the native framework directory are considered
        //   (e.g., \Windows\Microsoft.NET\Framework\v1.1.4322 for Visual Studio .NET 2003).
        //5. Assemblies in the registered assembly folders are considered.
        //   These are the directories discussed in the last section about adding assemblies to the list of .NET assemblies.
        //   If Visual Studio .NET 2005 with MSBuild is being used,
        //   HKLM\Software\Microsoft\ .NETFramework\v2.x.xxxxx\AssemblyFoldersEx will be considered first.
        //6. If Visual Studio .NET 2005 with MSBuild is being used and the assembly has a strong name,
        //   Visual Studio will look in the GAC for the assembly.

        IExternalAssemblyModuleInfo loadExternalAssemblyModule2(
            IExternalAssemblyOwner externalAssemblyOwner,
            ExternalAssemblyReferenceInfo externalAssemblyReferenceInfo
            )
        {
            string path = null;

            if (externalAssemblyReferenceInfo.moduleFrom == null)
            {
                //load assembly
                //priority:
                //1.HintPath
                //2.include
                //3.NET Framework directories
                //4.AssemblyFoldersEx directories
                //5.GAC

                //Hint path
                path = getPathAndCheckExists(externalAssemblyOwner, externalAssemblyReferenceInfo.hintPath);

                //include
                if (path == null &&
                    externalAssemblyReferenceInfo.assemblyInfo == null)
                {
                    path = getPathAndCheckExists(externalAssemblyOwner, externalAssemblyReferenceInfo.include);
                }

                //reference path (.user file)
                if (path == null &&
                    externalAssemblyReferenceInfo.referencePath != null &&
                    externalAssemblyReferenceInfo.include != null &&
                    externalAssemblyReferenceInfo.include.Contains(".dll"))
                {
                    string s = Path.Combine(externalAssemblyReferenceInfo.referencePath, externalAssemblyReferenceInfo.include);
                    path = getPathAndCheckExists(externalAssemblyOwner, s);
                }

                //.NET Framework directories
                if (path == null &&
                    externalAssemblyReferenceInfo.assemblyInfo != null &&
                    externalAssemblyReferenceInfo.assemblyInfo.Name != null)
                {
                    string frameworkDir;

                    if (string.Equals(externalAssemblyReferenceInfo.assemblyInfo.ProcessorArchitecture, "X86", StringComparison.InvariantCultureIgnoreCase))
                    {
                        frameworkDir = @"C:\Windows\Microsoft.NET\Framework";
                    }
                    else if (string.Equals(externalAssemblyReferenceInfo.assemblyInfo.ProcessorArchitecture, "AMD64", StringComparison.InvariantCultureIgnoreCase))
                    {
                        frameworkDir = @"C:\Windows\Microsoft.NET\Framework64";
                    }
                    else
                    {
                        unsafe
                        {
                            if (sizeof(IntPtr) == 4)
                            {
                                frameworkDir = @"C:\Windows\Microsoft.NET\Framework";
                            }
                            else
                            {
                                frameworkDir = @"C:\Windows\Microsoft.NET\Framework64";
                            }
                        }
                    }

                    string          requiredTargetFramework = externalAssemblyReferenceInfo.solutionRequiredTargetFramework;
                    AssemblyVersion av;
                    if (requiredTargetFramework != null)
                    {
                        av = getMinAssemblyVersionFromRequiredTargetFramework(requiredTargetFramework);
                    }
                    else
                    {
                        switch (externalAssemblyReferenceInfo.vs_version)
                        {
                        case Metaspec.vs_version.vsv_vs2002:
                            av = new AssemblyVersion(1, 0, 0, 0);
                            break;

                        case Metaspec.vs_version.vsv_vs2003:
                            av = new AssemblyVersion(1, 1, 0, 0);
                            break;

                        case Metaspec.vs_version.vsv_vs2005:
                            av = new AssemblyVersion(2, 0, 0, 0);
                            break;

                        case Metaspec.vs_version.vsv_vs2008:
                            av = new AssemblyVersion(3, 5, 0, 0);
                            break;

                        case Metaspec.vs_version.vsv_vs2010:
                            av = new AssemblyVersion(4, 0, 0, 0);
                            break;

                        default:
                            av = new AssemblyVersion(0, 0, 0, 0);
                            break;
                        }
                    }
                    if (externalAssemblyReferenceInfo.assemblyInfo.Version > av)
                    {
                        av = externalAssemblyReferenceInfo.assemblyInfo.Version;
                    }

                    vs_version vs_version = externalAssemblyReferenceInfo.vs_version;
                    if (av.MajorVersion >= 4)
                    {
                        vs_version = Metaspec.vs_version.vsv_vs2010;
                    }
                    else if (av.MajorVersion >= 3 &&
                             av.MinorVersion >= 5)
                    {
                        vs_version = Metaspec.vs_version.vsv_vs2008;
                    }
                    else if (av.MajorVersion >= 2)
                    {
                        vs_version = Metaspec.vs_version.vsv_vs2005;
                    }
                    else if (av.MajorVersion >= 1 &&
                             av.MinorVersion >= 1)
                    {
                        vs_version = Metaspec.vs_version.vsv_vs2003;
                    }
                    else if (av.MajorVersion >= 1)
                    {
                        vs_version = Metaspec.vs_version.vsv_vs2002;
                    }

                    bool loadFromAssembliesFoldersFlag = false;

                    {
                        while (vs_version != vs_version.vsv_unknown)
                        {
                            string dotnetVersionDir = null;

                            dotnetVersionDir = GetNetVersionDirectory(vs_version);

                            if (dotnetVersionDir != null)
                            {
                                string s = Path.Combine(frameworkDir, dotnetVersionDir);
                                s    = Path.Combine(s, externalAssemblyReferenceInfo.assemblyInfo.Name + ".dll");
                                path = getPathAndCheckExists(externalAssemblyOwner, s);
                                if (path != null)
                                {
                                    break;
                                }
                            }

                            if (path == null &&
                                !loadFromAssembliesFoldersFlag)
                            {
                                //AssembliesFolders
                                path = LoadFromAssembliesFolders(externalAssemblyOwner, externalAssemblyReferenceInfo, vs_version);
                                if (path != null)
                                {
                                    break;
                                }
                                loadFromAssembliesFoldersFlag = true;
                            }

                            --vs_version;
                        }
                    }
                }

                //GAC
                if (path == null)
                {
                    if (externalAssemblyReferenceInfo.assemblyInfo != null)
                    {
                        List <BetterAssemblyInfo> betterAssemblyInfo = new List <BetterAssemblyInfo>();

                        AssemblyCacheEnum ace = new AssemblyCacheEnum(externalAssemblyReferenceInfo.assemblyInfo.Name);
                        bool presentInCache   = false;
                        while (true)
                        {
                            string s = ace.GetNextAssembly();
                            if (string.IsNullOrEmpty(s))
                            {
                                break;
                            }
                            presentInCache = true;

                            Metaspec.AssemblyInfo ai = Metaspec.AssemblyInfo.parse(s);

                            if (ai != null)
                            {
                                betterAssemblyInfo.Add(new BetterAssemblyInfo(ai, s));
                            }
                        }

                        string sAssemblyInfo = selectBetterAssembly(externalAssemblyReferenceInfo, betterAssemblyInfo);
                        if (sAssemblyInfo != null)
                        {
                            path = AssemblyCache.QueryAssemblyInfo(sAssemblyInfo);
                        }
                    }
                }

                //OutputPath
                if (path == null &&
                    externalAssemblyReferenceInfo.outputPath != null &&
                    (externalAssemblyReferenceInfo.assemblyInfo.Name != null ||
                     (externalAssemblyReferenceInfo.include != null) &&
                     externalAssemblyReferenceInfo.include.Contains(".dll")))
                {
                    if (externalAssemblyReferenceInfo.assemblyInfo.Name != null)
                    {
                        string s = Path.Combine(externalAssemblyReferenceInfo.outputPath, externalAssemblyReferenceInfo.assemblyInfo.Name + ".dll");
                        path = getPathAndCheckExists(externalAssemblyOwner, s);
                    }
                    if (path == null &&
                        externalAssemblyReferenceInfo.include != null &&
                        externalAssemblyReferenceInfo.include.Contains(".dll"))
                    {
                        string s = Path.Combine(externalAssemblyReferenceInfo.outputPath, externalAssemblyReferenceInfo.include);
                        path = getPathAndCheckExists(externalAssemblyOwner, s);
                    }
                }
            }
            else
            {
                //load module
                path = Path.GetDirectoryName(externalAssemblyReferenceInfo.moduleFrom.getPath());
                path = Path.Combine(path, externalAssemblyReferenceInfo.modulePath);
            }

            if (path == null ||
                !File.Exists(path))
            {
                return(null);
            }

            IExternalAssemblyModuleInfo module_info = new IExternalAssemblyModuleInfo();

            module_info.shared_assembly = true;

            string pathUpper = path.ToUpper();

            if (!modules.ContainsKey(pathUpper))
            {
                byte[] bytes = File.ReadAllBytes(path);
                IExternalAssemblyModule module = IExternalAssemblyModuleFactory.create(bytes, path);
                module_info.module = module;
                modules.Add(pathUpper, module);
            }
            else
            {
                module_info.module = modules[pathUpper];
            }

            return(module_info);
        }
예제 #6
0
 public BetterAssemblyInfo(Metaspec.AssemblyInfo assemblyInfo, string sAssemblyInfo)
 {
     this.assemblyInfo  = assemblyInfo;
     this.sAssemblyInfo = sAssemblyInfo;
 }