コード例 #1
0
        public TargetPlatform GetTargetPlatform(string assemliyFilePath)
        {
            if (string.IsNullOrEmpty(assemliyFilePath))
            {
                return(TargetPlatform.None);
            }
            if (pathRepository.AssemblyParts.ContainsKey(assemliyFilePath))
            {
                return(pathRepository.AssemblyParts[assemliyFilePath]);
            }
            else
            {
                ModuleDefinition      moduleDef = ModuleDefinition.ReadModule(assemliyFilePath, readerParameters);
                AssemblyNameReference msCorlib  = moduleDef.AssemblyReferences.FirstOrDefault(a => a.Name == "mscorlib");

                if (msCorlib == null)
                {
                    msCorlib = moduleDef.AssemblyReferences.FirstOrDefault(x => x.Name == "System.Runtime");
                    if (msCorlib != null)
                    {
                        pathRepository.AssemblyParts.Add(assemliyFilePath, TargetPlatform.WinRT);
                        return(TargetPlatform.WinRT);
                    }
                    // the next line is only to keep the old functionality
                    msCorlib = moduleDef.Assembly.Name;
                }

                if (moduleDef.Assembly != null && moduleDef.Assembly.Name.IsWindowsRuntime || msCorlib.IsFakeMscorlibReference())
                {
                    pathRepository.AssemblyParts.Add(assemliyFilePath, TargetPlatform.WinRT);
                    return(TargetPlatform.WinRT);
                }

                /*AssemblyName assemblyName = new AssemblyName(msCorlib.Name,
                 *                                  msCorlib.FullName,
                 *                                  msCorlib.Version,
                 *                                  msCorlib.PublicKeyToken,
                 *                                  Path.GetDirectoryName(assemliyFilePath)) { TargetArchitecture = moduleDef.GetModuleArchitecture() };
                 * IEnumerable<string> foundPaths = GetAssemblyPaths(assemblyName);
                 *
                 * return GetTargetPlatform(foundPaths.FirstOrDefault());*/

                /*Telerik Authorship*/
                TargetArchitecture moduleArchitecture = moduleDef.GetModuleArchitecture();
                /*Telerik Authorship*/
                foreach (KeyValuePair <AssemblyName, TargetPlatform> pair in Mscorlibs)
                {
                    if (AreVersionEquals(pair.Key.Version, msCorlib.Version) &&
                        ArePublicKeyEquals(pair.Key.PublicKeyToken, msCorlib.PublicKeyToken) &&
                        moduleArchitecture.CanReference(pair.Key.TargetArchitecture))
                    {
                        pathRepository.AssemblyParts.Add(assemliyFilePath, pair.Value);
                        return(pair.Value);
                    }
                }

                /*Telerik Authorship*/
                return(TargetPlatform.None);
            }
        }
コード例 #2
0
        public TargetPlatform GetTargetPlatform(string assemblyFilePath, ModuleDefinition moduleDef)
        {
            TargetPlatform targetPlatform = this.DefaultTargetPlatform;

            if (string.IsNullOrEmpty(assemblyFilePath))
            {
                return(targetPlatform);
            }

            if (this.assemblyFrameworkResolverCache.AssemblyPathToTargetPlatform.ContainsKey(assemblyFilePath))
            {
                return(this.assemblyFrameworkResolverCache.AssemblyPathToTargetPlatform[assemblyFilePath]);
            }
            else
            {
                Task <TargetPlatform> targetPlatformFromDepsJson = null;

                string moduleLocation   = moduleDef.FullyQualifiedName ?? moduleDef.FilePath;
                string depsJsonLocation = Directory.GetFiles(Path.GetDirectoryName(moduleLocation), "*.deps.json").FirstOrDefault();

                if (File.Exists(depsJsonLocation))
                {
                    targetPlatformFromDepsJson = Task.Factory.StartNew(() =>
                    {
                        return(this.GetPlatformTargetFromDepsJson(moduleLocation));
                    });
                }

                ///*Telerik Authorship*/
                if (moduleDef.Assembly != null)
                {
                    targetPlatform = this.GetTargetPlatform(moduleDef);

                    if (targetPlatform != this.DefaultTargetPlatform)
                    {
                        this.assemblyFrameworkResolverCache.AddAssemblyTargetPlatformToCache(assemblyFilePath, targetPlatform);
                        return(targetPlatform);
                    }
                }

                AssemblyNameReference msCorlib = moduleDef.AssemblyReferences.FirstOrDefault(a => a.Name == "mscorlib");

                if (msCorlib == null)
                {
                    AssemblyNameReference systemRuntimeReference = moduleDef.AssemblyReferences.FirstOrDefault(x => x.Name == "System.Runtime");
                    targetPlatform = this.GetTargetPlatform(systemRuntimeReference);

                    if (targetPlatform != this.DefaultTargetPlatform)
                    {
                        this.assemblyFrameworkResolverCache.AddAssemblyTargetPlatformToCache(assemblyFilePath, targetPlatform);
                        this.assemblyFrameworkResolverCache.AddAssemblySystemRuntimeReference(assemblyFilePath, systemRuntimeReference);

                        return(targetPlatform);
                    }

                    // the next line is only to keep the old functionality
                    msCorlib = moduleDef.Assembly.Name;
                }

                if (moduleDef.Assembly != null && moduleDef.Assembly.Name.IsWindowsRuntime || msCorlib.IsFakeMscorlibReference())
                {
                    this.assemblyFrameworkResolverCache.AddAssemblyTargetPlatformToCache(assemblyFilePath, TargetPlatform.WinRT);
                    return(TargetPlatform.WinRT);
                }

                /*AssemblyName assemblyName = new AssemblyName(msCorlib.Name,
                 *                                  msCorlib.FullName,
                 *                                  msCorlib.Version,
                 *                                  msCorlib.PublicKeyToken,
                 *                                  Path.GetDirectoryName(assemliyFilePath)) { TargetArchitecture = moduleDef.GetModuleArchitecture() };
                 * IEnumerable<string> foundPaths = GetAssemblyPaths(assemblyName);
                 *
                 * return GetTargetPlatform(foundPaths.FirstOrDefault());*/

                /*Telerik Authorship*/
                if (targetPlatformFromDepsJson != null)
                {
                    targetPlatformFromDepsJson.Wait();
                    targetPlatform = targetPlatformFromDepsJson.Result;

                    if (targetPlatform != this.DefaultTargetPlatform)
                    {
                        this.assemblyFrameworkResolverCache.AddAssemblyTargetPlatformToCache(assemblyFilePath, targetPlatform);
                        return(targetPlatform);
                    }
                }

                /*Telerik Authorship*/
                TargetArchitecture moduleArchitecture = moduleDef.GetModuleArchitecture();
                /*Telerik Authorship*/
                foreach (KeyValuePair <AssemblyName, TargetPlatform> pair in Mscorlibs)
                {
                    if (AssemblyNameComparer.AreVersionEquals(pair.Key.Version, msCorlib.Version) &&
                        AssemblyNameComparer.ArePublicKeyEquals(pair.Key.PublicKeyToken, msCorlib.PublicKeyToken) &&
                        moduleArchitecture.CanReference(pair.Key.TargetArchitecture))
                    {
                        this.assemblyFrameworkResolverCache.AddAssemblyTargetPlatformToCache(assemblyFilePath, pair.Value);
                        return(pair.Value);
                    }
                }

                /*Telerik Authorship*/
                this.assemblyFrameworkResolverCache.AddAssemblyTargetPlatformToCache(assemblyFilePath, this.DefaultTargetPlatform);
                return(this.DefaultTargetPlatform);
            }
        }