Пример #1
0
        public override AssemblyDefinition Resolve(AssemblyNameReference name)
        {
            var    targetFramework = TargetFramework.Split(new[] { ",Version=v" }, StringSplitOptions.None);
            string file            = null;

            switch (targetFramework[0])
            {
            case ".NETCoreApp":
            case ".NETStandard":
                if (targetFramework.Length != 2)
                {
                    goto default;
                }
                if (dotNetCorePathFinder == null)
                {
                    var version = targetFramework[1].Length == 3 ? targetFramework[1] + ".0" : targetFramework[1];
                    dotNetCorePathFinder = new DotNetCorePathFinder(assemblyFileName, TargetFramework, version, this.loadedAssemblyReferences);
                }
                file = dotNetCorePathFinder.TryResolveDotNetCore(name);
                if (file == null)
                {
                    string dir = Path.GetDirectoryName(assemblyFileName);
                    if (File.Exists(Path.Combine(dir, name.Name + ".dll")))
                    {
                        file = Path.Combine(dir, name.Name + ".dll");
                    }
                    else if (File.Exists(Path.Combine(dir, name.Name + ".exe")))
                    {
                        file = Path.Combine(dir, name.Name + ".exe");
                    }
                }
                if (file == null)
                {
                    return(base.Resolve(name));
                }
                else
                {
                    return(ModuleDefinition.ReadModule(file, new ReaderParameters()
                    {
                        AssemblyResolver = this
                    }).Assembly);
                }

            default:
                return(base.Resolve(name));
            }
        }
Пример #2
0
        public static string FindAssemblyFile(AssemblyDefinition assemblyDefinition, string assemblyFile)
        {
            var assemblyName = assemblyDefinition.Name;

            var detectedTargetFramework = assemblyDefinition.DetectTargetFrameworkId(assemblyFile);

            if (string.IsNullOrEmpty(detectedTargetFramework))
            {
                // Without a target framework id it makes no sense to continue
                return(null);
            }

            var    targetFramework = detectedTargetFramework.Split(new[] { ",Version=v" }, StringSplitOptions.None);
            string file            = null;

            switch (targetFramework[0])
            {
            case ".NETCoreApp":
            case ".NETStandard":
                if (targetFramework.Length != 2)
                {
                    return(FindAssemblyFromGAC(assemblyDefinition));
                }
                var version = targetFramework[1].Length == 3 ? targetFramework[1] + ".0" : targetFramework[1];
                var dotNetCorePathFinder = new DotNetCorePathFinder(assemblyFile, detectedTargetFramework, version);
                file = dotNetCorePathFinder.TryResolveDotNetCore(assemblyName);
                if (file != null)
                {
                    return(file);
                }
                return(FindAssemblyFromGAC(assemblyDefinition));

            default:
                return(FindAssemblyFromGAC(assemblyDefinition));
            }
        }
Пример #3
0
        LoadedAssembly LookupReferencedAssemblyInternal(string fullName)
        {
            foreach (LoadedAssembly asm in assemblyList.GetAssemblies())
            {
                if (asm.AssemblyDefinition != null && fullName.Equals(asm.AssemblyDefinition.FullName, StringComparison.OrdinalIgnoreCase))
                {
                    return(asm);
                }
            }
            if (assemblyLoadDisableCount > 0)
            {
                return(null);
            }

            if (!App.Current.Dispatcher.CheckAccess())
            {
                // Call this method on the GUI thread.
                return((LoadedAssembly)App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Func <string, LoadedAssembly>(LookupReferencedAssembly), fullName));
            }

            var    targetFramework = TargetFrameworkId.Split(new[] { ",Version=v" }, StringSplitOptions.None);
            var    name            = AssemblyNameReference.Parse(fullName);
            string file            = null;

            switch (targetFramework[0])
            {
            case ".NETCoreApp":
            case ".NETStandard":
                if (targetFramework.Length != 2)
                {
                    break;
                }
                if (dotNetCorePathFinder == null)
                {
                    var version = targetFramework[1].Length == 3 ? targetFramework[1] + ".0" : targetFramework[1];
                    dotNetCorePathFinder = new DotNetCorePathFinder(fileName, TargetFrameworkId, version, this.loadedAssemblyReferences);
                }
                file = dotNetCorePathFinder.TryResolveDotNetCore(name);
                break;

            default:
                file = GacInterop.FindAssemblyInNetGac(name);
                break;
            }
            if (file == null)
            {
                string dir = Path.GetDirectoryName(this.fileName);
                if (File.Exists(Path.Combine(dir, name.Name + ".dll")))
                {
                    file = Path.Combine(dir, name.Name + ".dll");
                }
                else if (File.Exists(Path.Combine(dir, name.Name + ".exe")))
                {
                    file = Path.Combine(dir, name.Name + ".exe");
                }
            }
            if (file != null)
            {
                loadedAssemblyReferences.AddMessage(fullName, MessageKind.Info, "Success - Loading from: " + file);
                return(assemblyList.OpenAssembly(file, true));
            }
            else
            {
                loadedAssemblyReferences.AddMessage(fullName, MessageKind.Error, "Could not find reference: " + fullName);
                return(null);
            }
        }