예제 #1
0
        /// <summary>
        /// Gets the file name for an assembly stored in the GAC.
        /// </summary>
        public FileName FindAssemblyInNetGac(DomAssemblyName reference)
        {
            // without public key, it can't be in the GAC
            if (reference.PublicKeyToken == null)
            {
                return(null);
            }

            for (int iext = 0; iext < extensions.Length; iext++)
            {
                for (int ipath = 0; ipath < gac_paths.Length; ipath++)
                {
                    for (int igac = 0; igac < gacs.Length; igac++)
                    {
                        var gac  = Path.Combine(gac_paths[ipath], gacs[igac]);
                        var file = GetAssemblyFile(reference, prefixes[ipath], gac, extensions[iext]);
                        if (File.Exists(file))
                        {
                            return(FileName.Create(file));
                        }
                    }
                }
            }

            return(null);
        }
예제 #2
0
        static string GetAssemblyFile(DomAssemblyName reference, string prefix, string gac, string ext)
        {
            var gac_folder = new StringBuilder()
                             .Append(prefix)
                             .Append(reference.Version)
                             .Append("__");

            gac_folder.Append(reference.PublicKeyToken);

            return(Path.Combine(
                       Path.Combine(
                           Path.Combine(gac, reference.ShortName), gac_folder.ToString()),
                       reference.ShortName + ext));
        }
        public FileName FindAssembly(DomAssemblyName fullName)
        {
            FileName foundFileName = null;

            // Run through all searchers until we find something
            foreach (var searcher in searcherList)
            {
                if (searcher != null)
                {
                    foundFileName = searcher.FindAssembly(fullName);
                    if (foundFileName != null)
                    {
                        break;
                    }
                }
            }

            return(foundFileName);
        }
        public ICSharpCode.Core.FileName FindAssembly(DomAssemblyName fullName)
        {
            // Try to find assembly among solution projects
            IProjectService projectService = SD.GetRequiredService <IProjectService>();

            ProjectItem projectItem =
                project.Items.FirstOrDefault(
                    item => {
                if (item.ItemType == ItemType.COMReference)
                {
                    // Special handling for COM references: Their assembly names are prefixed with "Interop."
                    return(fullName.ShortName == "Interop." + item.Include);
                }
                if ((item.ItemType == ItemType.ProjectReference) && (item is ProjectReferenceProjectItem))
                {
                    // Special handling for project references: Compare with project name instead of file name
                    return(((ProjectReferenceProjectItem)item).ProjectName == fullName.ShortName);
                }
                return((item.ItemType == ItemType.Reference) && (item.Include == fullName.ShortName));
            });

            if (projectItem != null)
            {
                if (projectItem is ProjectReferenceProjectItem)
                {
                    // This is a project reference, so FileName delivers the project file instead of assembly binary
                    IProject refProject = ((ProjectReferenceProjectItem)projectItem).ReferencedProject;
                    if (refProject != null)
                    {
                        return(refProject.OutputAssemblyFullPath);
                    }
                }
                else
                {
                    return(projectItem.FileName);
                }
            }

            return(null);
        }
        public FileName FindAssembly(DomAssemblyName fullName)
        {
            // look for the assembly in the current loaded assembly lists
            var classBrowser = SD.GetRequiredService <IClassBrowser>();
            var relevantClassBrowserAssemblies = classBrowser.AssemblyLists
                                                 .Where(l => l.Assemblies.Any(a => a.Location == mainAssemblyFileName))
                                                 .SelectMany(l => l.Assemblies);

            foreach (var asm in relevantClassBrowserAssemblies)
            {
                if (asm.FullAssemblyName == fullName.FullName)
                {
                    return(asm.Location);
                }
            }

            // look in GAC
            var gacFileName = SD.GlobalAssemblyCache.FindAssemblyInNetGac(fullName);

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

            // scan current directory
            var fileName = baseDirectory.CombineFile(fullName.ShortName + ".dll");

            if (File.Exists(fileName))
            {
                return(fileName);
            }

            fileName = baseDirectory.CombineFile(fullName.ShortName + ".exe");
            if (File.Exists(fileName))
            {
                return(fileName);
            }
            return(null);
        }
예제 #6
0
        /// <summary>
        /// Gets the full display name of the GAC assembly of the specified short name
        /// </summary>
        public DomAssemblyName FindBestMatchingAssemblyName(DomAssemblyName reference)
        {
            string[] info;
            Version  requiredVersion = reference.Version;
            string   publicKey       = reference.PublicKeyToken;

            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName;

            Fusion.CreateAssemblyNameObject(out assemblyName, reference.ShortName, 0, 0);
            Fusion.CreateAssemblyEnum(out assemblyEnum, null, assemblyName, 2, 0);
            List <string> names = new List <string>();

            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);

                StringBuilder sb = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(sb, ref nChars, 0);

                string fullName = sb.ToString();
                if (publicKey != null)
                {
                    info = fullName.Split(',');
                    if (publicKey != info[3].Substring(info[3].LastIndexOf('=') + 1))
                    {
                        // Assembly has wrong public key
                        continue;
                    }
                }
                names.Add(fullName);
            }
            if (names.Count == 0)
            {
                return(null);
            }
            string  best        = null;
            Version bestVersion = null;
            Version currentVersion;

            if (requiredVersion != null)
            {
                // use assembly with lowest version higher or equal to required version
                for (int i = 0; i < names.Count; i++)
                {
                    info           = names[i].Split(',');
                    currentVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1));
                    if (currentVersion.CompareTo(requiredVersion) < 0)
                    {
                        continue;                         // version not good enough
                    }
                    if (best == null || currentVersion.CompareTo(bestVersion) < 0)
                    {
                        bestVersion = currentVersion;
                        best        = names[i];
                    }
                }
                if (best != null)
                {
                    return(new DomAssemblyName(best));
                }
            }
            // use assembly with highest version
            best        = names[0];
            info        = names[0].Split(',');
            bestVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1));
            for (int i = 1; i < names.Count; i++)
            {
                info           = names[i].Split(',');
                currentVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1));
                if (currentVersion.CompareTo(bestVersion) > 0)
                {
                    bestVersion = currentVersion;
                    best        = names[i];
                }
            }
            return(new DomAssemblyName(best));
        }