示例#1
0
        public void PreBuildEvents(ICsProject pProject, string pPathToCompiler, bool pDebug)
        {
            byte[] assemblyBuffer          = File.ReadAllBytes(pPathToCompiler + @"\\flash\\flash.dll");
            IExternalAssemblyModule module = IExternalAssemblyModuleFactory.create(assemblyBuffer, pPathToCompiler);

            pProject.addExternalAssemblyModules(new[] { module }, false, null);
        }
示例#2
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);
        }