Exemple #1
0
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="identity">Identity string to parse</param>
            /// <param name="identityType">Type of the identity</param>
            internal Identity(string identity, PublishInfo.IdentityType identityType)
            {
                System.Text.RegularExpressions.Match    regexMatch;
                System.Reflection.ProcessorArchitecture architecture;

                this.IdentityType = identityType;

                try
                {
                    // Parse application name
                    this.ApplicationName = identity.Substring(0, identity.IndexOf(','));

                    // Parse version
                    regexMatch   = _versionRegex.Match(identity);
                    this.Version = new System.Version(int.Parse(regexMatch.Groups["Major"].ToString()),
                                                      int.Parse(regexMatch.Groups["Minor"].ToString()),
                                                      int.Parse(regexMatch.Groups["Build"].ToString()),
                                                      int.Parse(regexMatch.Groups["Revision"].ToString()));

                    // Parse public key token
                    regexMatch          = _publicKeyTokenRegex.Match(identity);
                    this.PublicKeyToken = regexMatch.Groups["PublicKeyToken"].ToString();

                    // Parse processor architecture
                    regexMatch = _processorArchitectureRegex.Match(identity);
                    if (!System.Enum.TryParse <System.Reflection.ProcessorArchitecture>(
                            regexMatch.Groups["ProcessorArchitecture"].ToString(), true, out architecture))
                    {
                        architecture = System.Reflection.ProcessorArchitecture.None;
                    }
                    this.ProcessorArchitecture = architecture;
                }
                catch { }
            }
 /// <summary>
 /// Construct.
 /// </summary>
 public AssemblyFoldersFromConfigResolver(string searchPathElement, GetAssemblyName getAssemblyName,
     FileExists fileExists, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVesion,
     ProcessorArchitecture targetProcessorArchitecture, bool compareProcessorArchitecture,
     IBuildEngine buildEngine, TaskLoggingHelper log)
     : base(
         searchPathElement, getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVesion,
         targetProcessorArchitecture, compareProcessorArchitecture)
 {
     _buildEngine = buildEngine as IBuildEngine4;
     _taskLogger = log;
 }
 /// <summary>
 /// Construct.
 /// </summary>
 public AssemblyFoldersFromConfigResolver(string searchPathElement, GetAssemblyName getAssemblyName,
                                          FileExists fileExists, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVesion,
                                          ProcessorArchitecture targetProcessorArchitecture, bool compareProcessorArchitecture,
                                          IBuildEngine buildEngine, TaskLoggingHelper log)
     : base(
         searchPathElement, getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVesion,
         targetProcessorArchitecture, compareProcessorArchitecture)
 {
     _buildEngine = buildEngine as IBuildEngine4;
     _taskLogger  = log;
 }
 /// <summary>
 /// Aplica a arquitetura.
 /// </summary>
 /// <param name="processorArchitecture"></param>
 /// <returns></returns>
 private bool ApplyArchitecture(System.Reflection.ProcessorArchitecture processorArchitecture)
 {
     if (((_currentLoadedArchitecture == System.Reflection.ProcessorArchitecture.Amd64) || (_currentLoadedArchitecture == System.Reflection.ProcessorArchitecture.IA64)) || (_currentLoadedArchitecture == System.Reflection.ProcessorArchitecture.X86))
     {
         return(this.IsCompatible(_currentLoadedArchitecture, processorArchitecture));
     }
     if (_currentLoadedArchitecture != System.Reflection.ProcessorArchitecture.MSIL)
     {
         return(false);
     }
     _currentLoadedArchitecture = processorArchitecture;
     if (processorArchitecture == System.Reflection.ProcessorArchitecture.None)
     {
         return(false);
     }
     return(true);
 }
        internal AssemblyFoldersEx
        (
            string registryKeyRoot,
            string targetRuntimeVersion,
            string registryKeySuffix,
            string osVersion,
            string platform,
            GetRegistrySubKeyNames getRegistrySubKeyNames,
            GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue,
            ProcessorArchitecture targetProcessorArchitecture,
            OpenBaseKey openBaseKey
        )
        {
            // No extensions are supported, except on Windows
            if (!NativeMethodsShared.IsWindows)
            {
                return;
            }

            bool is64bitOS      = EnvironmentUtilities.Is64BitOperatingSystem;
            bool targeting64bit = targetProcessorArchitecture == ProcessorArchitecture.Amd64 || targetProcessorArchitecture == ProcessorArchitecture.IA64;

            // The registry lookup should be as follows:

            /* 64 bit OS:
             *            Targeting 64 bit:
             *                First, look in 64 bit registry location
             *                Second, look in 32 bit registry location
             *            Targeting X86 or MSIL:
             *                First,  look in the 32 bit hive
             *                Second, look in 64 bit hive
             *
             *  32 bit OS:
             *        32 bit process:
             *            Targeting 64 bit, or X86, or MSIL:
             *                Look in the default registry which is the 32 bit hive
             */

            // Under WOW64 the HKEY_CURRENT_USER\SOFTWARE key is shared. This means the values are the same in the 64 bit and 32 bit views. This means we only need to get one view of this key.
            FindDirectories(RegistryView.Default, RegistryHive.CurrentUser, registryKeyRoot, targetRuntimeVersion, registryKeySuffix, osVersion, platform, getRegistrySubKeyNames, getRegistrySubKeyDefaultValue, openBaseKey);

            if (is64bitOS)
            {
                // Under WOW64 the HKEY_LOCAL_MACHINE\SOFTWARE key is redirected. This means the values can be different in the 64 bit and 32 bit views. This means we only need to get look at both keys.

                if (targeting64bit)
                {
                    FindDirectories(RegistryView.Registry64, RegistryHive.LocalMachine, registryKeyRoot, targetRuntimeVersion, registryKeySuffix, osVersion, platform, getRegistrySubKeyNames, getRegistrySubKeyDefaultValue, openBaseKey);
                    FindDirectories(RegistryView.Registry32, RegistryHive.LocalMachine, registryKeyRoot, targetRuntimeVersion, registryKeySuffix, osVersion, platform, getRegistrySubKeyNames, getRegistrySubKeyDefaultValue, openBaseKey);
                }
                else
                {
                    FindDirectories(RegistryView.Registry32, RegistryHive.LocalMachine, registryKeyRoot, targetRuntimeVersion, registryKeySuffix, osVersion, platform, getRegistrySubKeyNames, getRegistrySubKeyDefaultValue, openBaseKey);
                    FindDirectories(RegistryView.Registry64, RegistryHive.LocalMachine, registryKeyRoot, targetRuntimeVersion, registryKeySuffix, osVersion, platform, getRegistrySubKeyNames, getRegistrySubKeyDefaultValue, openBaseKey);
                }
            }
            else
            {
                FindDirectories(RegistryView.Default, RegistryHive.LocalMachine, registryKeyRoot, targetRuntimeVersion, registryKeySuffix, osVersion, platform, getRegistrySubKeyNames, getRegistrySubKeyDefaultValue, openBaseKey);
            }
        }
        internal AssemblyFoldersFromConfig(string configFile, string targetRuntimeVersion, ProcessorArchitecture targetArchitecture)
        {
            ErrorUtilities.VerifyThrowArgumentNull(configFile, nameof(configFile));
            ErrorUtilities.VerifyThrowArgumentNull(targetRuntimeVersion, nameof(targetRuntimeVersion));

            var collection      = AssemblyFolderCollection.Load(configFile);
            var assemblyTargets = GatherVersionStrings(targetRuntimeVersion, collection);

            bool targeting64Bit = targetArchitecture == ProcessorArchitecture.Amd64 ||
                                  targetArchitecture == ProcessorArchitecture.IA64;

            // Platform-agnostic folders first.
            FindDirectories(assemblyTargets, target => string.IsNullOrEmpty(target.Platform));

            if (EnvironmentUtilities.Is64BitOperatingSystem)
            {
                if (targeting64Bit)
                {
                    FindDirectories(assemblyTargets,
                                    target => !string.IsNullOrEmpty(target.Platform) && target.Platform.Equals("x64", StringComparison.OrdinalIgnoreCase));
                    FindDirectories(assemblyTargets,
                                    target => !string.IsNullOrEmpty(target.Platform) && target.Platform.Equals("x86", StringComparison.OrdinalIgnoreCase));
                }
                else
                {
                    FindDirectories(assemblyTargets,
                                    target => !string.IsNullOrEmpty(target.Platform) && target.Platform.Equals("x86", StringComparison.OrdinalIgnoreCase));
                    FindDirectories(assemblyTargets,
                                    target => !string.IsNullOrEmpty(target.Platform) && target.Platform.Equals("x64", StringComparison.OrdinalIgnoreCase));
                }
            }
            else
            {
                FindDirectories(assemblyTargets,
                                target => !string.IsNullOrEmpty(target.Platform) && target.Platform.Equals("x86", StringComparison.OrdinalIgnoreCase));
            }
        }
 public AssemblyFoldersExResolver(string searchPathElement, GetAssemblyName getAssemblyName, FileExists fileExists, GetRegistrySubKeyNames getRegistrySubKeyNames, GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue, GetAssemblyRuntimeVersion getRuntimeVersion, OpenBaseKey openBaseKey, Version targetedRuntimeVesion, ProcessorArchitecture targetProcessorArchitecture, bool compareProcessorArchitecture, IBuildEngine buildEngine)
     : base(searchPathElement, getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVesion, targetProcessorArchitecture, compareProcessorArchitecture)
 {
     _buildEngine                   = buildEngine as IBuildEngine4;
     _getRegistrySubKeyNames        = getRegistrySubKeyNames;
     _getRegistrySubKeyDefaultValue = getRegistrySubKeyDefaultValue;
     _openBaseKey                   = openBaseKey;
 }
Exemple #8
0
 public static System.Collections.Generic.IList <Microsoft.Build.Utilities.AssemblyFoldersFromConfigInfo> GetAssemblyFoldersFromConfigInfo(string configFile, string targetFrameworkVersion, System.Reflection.ProcessorArchitecture targetProcessorArchitecture)
 {
     throw null;
 }
Exemple #9
0
        /// <summary>
        /// Compile search paths into an array of resolvers.
        /// </summary>
        /// <param name="buildEngine"></param>
        /// <param name="searchPaths"></param>
        /// <param name="candidateAssemblyFiles">Paths to assembly files mentioned in the project.</param>
        /// <param name="targetProcessorArchitecture">Like x86 or IA64\AMD64, the processor architecture being targetted.</param>
        /// <param name="frameworkPaths">Paths to FX folders.</param>
        /// <param name="fileExists"></param>
        /// <param name="getAssemblyName"></param>
        /// <param name="getRegistrySubKeyNames"></param>
        /// <param name="getRegistrySubKeyDefaultValue"></param>
        /// <param name="openBaseKey"></param>
        /// <param name="installedAssemblies"></param>
        /// <param name="getRuntimeVersion"></param>
        /// <param name="targetedRuntimeVersion"></param>
        /// <param name="getAssemblyPathInGac"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        public static Resolver[] CompileSearchPaths
        (
            IBuildEngine buildEngine,
            string[] searchPaths,
            string[] candidateAssemblyFiles,
            System.Reflection.ProcessorArchitecture targetProcessorArchitecture,
            string[] frameworkPaths,
            FileExists fileExists,
            GetAssemblyName getAssemblyName,
#if FEATURE_WIN32_REGISTRY
            GetRegistrySubKeyNames getRegistrySubKeyNames,
            GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue,
            OpenBaseKey openBaseKey,
#endif
            InstalledAssemblies installedAssemblies,
            GetAssemblyRuntimeVersion getRuntimeVersion,
            Version targetedRuntimeVersion,
            GetAssemblyPathInGac getAssemblyPathInGac,
            TaskLoggingHelper log
        )
        {
            var resolvers = new Resolver[searchPaths.Length];

            for (int p = 0; p < searchPaths.Length; ++p)
            {
                string basePath = searchPaths[p];

                // Was {HintPathFromItem} specified? If so, take the Item's
                // HintPath property.
                if (0 == String.Compare(basePath, AssemblyResolutionConstants.hintPathSentinel, StringComparison.OrdinalIgnoreCase))
                {
                    resolvers[p] = new HintPathResolver(searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion);
                }
                else if (0 == String.Compare(basePath, AssemblyResolutionConstants.frameworkPathSentinel, StringComparison.OrdinalIgnoreCase))
                {
                    resolvers[p] = new FrameworkPathResolver(frameworkPaths, installedAssemblies, searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion);
                }
                else if (0 == String.Compare(basePath, AssemblyResolutionConstants.rawFileNameSentinel, StringComparison.OrdinalIgnoreCase))
                {
                    resolvers[p] = new RawFilenameResolver(searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion);
                }
                else if (0 == String.Compare(basePath, AssemblyResolutionConstants.candidateAssemblyFilesSentinel, StringComparison.OrdinalIgnoreCase))
                {
                    resolvers[p] = new CandidateAssemblyFilesResolver(candidateAssemblyFiles, searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion);
                }
#if FEATURE_GAC
                else if (0 == String.Compare(basePath, AssemblyResolutionConstants.gacSentinel, StringComparison.OrdinalIgnoreCase))
                {
                    resolvers[p] = new GacResolver(targetProcessorArchitecture, searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion, getAssemblyPathInGac);
                }
#endif
                else if (0 == String.Compare(basePath, AssemblyResolutionConstants.assemblyFoldersSentinel, StringComparison.OrdinalIgnoreCase))
                {
                    resolvers[p] = new AssemblyFoldersResolver(searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion);
                }
#if FEATURE_WIN32_REGISTRY
                // Check for AssemblyFoldersEx sentinel.
                else if (0 == String.Compare(basePath, 0, AssemblyResolutionConstants.assemblyFoldersExSentinel, 0, AssemblyResolutionConstants.assemblyFoldersExSentinel.Length, StringComparison.OrdinalIgnoreCase))
                {
                    resolvers[p] = new AssemblyFoldersExResolver(searchPaths[p], getAssemblyName, fileExists, getRegistrySubKeyNames, getRegistrySubKeyDefaultValue, getRuntimeVersion, openBaseKey, targetedRuntimeVersion, targetProcessorArchitecture, true, buildEngine);
                }
#endif
                else if (0 == String.Compare(basePath, 0, AssemblyResolutionConstants.assemblyFoldersFromConfigSentinel, 0, AssemblyResolutionConstants.assemblyFoldersFromConfigSentinel.Length, StringComparison.OrdinalIgnoreCase))
                {
                    resolvers[p] = new AssemblyFoldersFromConfigResolver(searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion, targetProcessorArchitecture, true, buildEngine, log);
                }
                else
                {
                    resolvers[p] = new DirectoryResolver(searchPaths[p], getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVersion);
                }
            }
            return(resolvers);
        }
 /// <summary>
 /// Construct.
 /// </summary>
 /// <param name="targetProcessorArchitecture">Like x86 or IA64\AMD64, the processor architecture being targeted.</param>
 /// <param name="searchPathElement">The search path element.</param>
 /// <param name="getAssemblyName">Delegate to get the assembly name object.</param>
 /// <param name="fileExists">Delegate to check if the file exists.</param>
 /// <param name="getRuntimeVersion">Delegate to get the runtime version.</param>
 /// <param name="targetedRuntimeVesion">The targeted runtime version.</param>
 /// <param name="getAssemblyPathInGac">Delegate to get assembly path in the GAC.</param>
 public GacResolver(System.Reflection.ProcessorArchitecture targetProcessorArchitecture, string searchPathElement, GetAssemblyName getAssemblyName, FileExists fileExists, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVesion, GetAssemblyPathInGac getAssemblyPathInGac)
     : base(searchPathElement, getAssemblyName, fileExists, getRuntimeVersion, targetedRuntimeVesion, targetProcessorArchitecture, true)
 {
     _getAssemblyPathInGac = getAssemblyPathInGac;
 }
 /// <summary>
 ///  Checks to see if the assemblyName passed in is in the GAC.
 /// </summary>
 private static string GetPathForAssemblyInGac(AssemblyNameExtension assemblyName, ProcessorArchitecture targetProcessorArchitecture, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVersion, FileExists fileExists, bool fullFusionName, bool specificVersion)
 {
     if (assemblyName.Equals(new AssemblyNameExtension("V, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null")))
     {
         return null;
     }
     else if (assemblyName.Equals(new AssemblyNameExtension("W, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null")))
     {
         return @"C:\MyComponents2\W.dll";
     }
     else if (assemblyName.Equals(new AssemblyNameExtension("Z, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null")))
     {
         return null;
     }
     else if (assemblyName.Equals(new AssemblyNameExtension("X, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null")))
     {
         return @"C:\MyComponents\X.dll";
     }
     else if (assemblyName.Equals(new AssemblyNameExtension("Y, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null")))
     {
         return null;
     }
     else
     {
         string gacLocation = null;
         if (assemblyName.Version != null)
         {
             gacLocation = GlobalAssemblyCache.GetLocation(assemblyName, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, fullFusionName, fileExists, null, null, specificVersion /* this value does not matter if we are passing a full fusion name*/);
         }
         return gacLocation;
     }
 }
        /// <summary>
        /// Analiza o assembly informado.
        /// </summary>
        /// <param name="assemblyName"></param>
        /// <param name="throwWhenMissing"></param>
        /// <returns></returns>
        public AsmData AnalyzeRootAssembly(string assemblyName, bool throwWhenMissing)
        {
            _cache = new Dictionary <string, AsmData>();
            _circularDependencyWarningShown = false;
            _parentsStack = new Stack <string>();
            _workingDir   = Environment.CurrentDirectory;
            string  fullPath = System.IO.Path.GetFullPath(assemblyName);
            AsmData ret      = new AsmData(assemblyName, fullPath);
            var     domain   = AppDomain.CurrentDomain;

            try
            {
                if (!System.IO.File.Exists(assemblyName))
                {
                    ret.Path             = "";
                    ret.Validity         = AsmData.AsmValidity.Invalid;
                    ret.AssemblyFullName = "";
                    return(ret);
                }
                System.Reflection.Assembly asm = null;
                try
                {
                    using (var stream = System.IO.File.OpenRead(fullPath))
                    {
                        var raw = new byte[stream.Length];
                        stream.Read(raw, 0, raw.Length);
                        try
                        {
                            asm          = domain.Load(raw);
                            ret.Validity = AsmData.AsmValidity.Valid;
                        }
                        catch (Exception)
                        {
                            asm          = System.Reflection.Assembly.ReflectionOnlyLoad(raw);
                            ret.Validity = AsmData.AsmValidity.ReferencesOnly;
                        }
                    }
                }
                catch (Exception)
                {
                    asm          = null;
                    ret.Validity = AsmData.AsmValidity.Invalid;
                }
                if (asm != null)
                {
                    ret.AssemblyFullName       = asm.FullName;
                    ret.Path                   = fullPath;
                    ret.Architecture           = asm.GetName().ProcessorArchitecture;
                    _currentLoadedArchitecture = ret.Architecture;
                    string tempName = asm.GetName().Name;
                    if (!this.assemblyNameToPathMap.ContainsKey(tempName))
                    {
                        this.assemblyNameToPathMap.Add(tempName, asm.Location);
                    }
                    string cfgFilePath = Redirection.FindConfigFile(ret.Path);
                    if (!string.IsNullOrEmpty(cfgFilePath) && !_allVersionRedirections.ContainsKey(fullPath))
                    {
                        var             versionRedirections = Redirection.GetVersionRedirections(cfgFilePath);
                        PathRedirection pathRedirections    = Redirection.GetPathRedirections(ret.AssemblyFullName, cfgFilePath);
                        _allVersionRedirections.Add(fullPath, versionRedirections);
                        _probingPaths.Add(ret.AssemblyFullName, pathRedirections);
                    }
                    var references = asm.GetReferencedAssemblies().ToList();
                    var fileName   = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(fullPath), string.Format("{0}.XmlSerializers{1}", System.IO.Path.GetFileNameWithoutExtension(fullPath), System.IO.Path.GetExtension(fullPath)));
                    if (System.IO.File.Exists(fileName))
                    {
                        references.Add(System.Reflection.AssemblyName.GetAssemblyName(fileName));
                    }
                    _totalReferencedAssemblies = references.Count;
                    _parentsStack.Push(ret.AssemblyFullName);
                    foreach (System.Reflection.AssemblyName asmName in references)
                    {
                        this.AnalyzeAssembly(asmName, ret, domain, throwWhenMissing);
                        _assembliesFinished++;
                        if (_bgWorker != null)
                        {
                            _bgWorker.ReportProgress((100 * _assembliesFinished) / _totalReferencedAssemblies);
                        }
                    }
                    _parentsStack.Pop();
                }
            }
            finally
            {
            }
            return(ret);
        }
 /// <summary>
 /// Verifica se as arquiteturas são compatíveis.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="child"></param>
 /// <returns></returns>
 private bool IsCompatible(System.Reflection.ProcessorArchitecture parent, System.Reflection.ProcessorArchitecture child)
 {
     return(_architectureCompatibilityMatrix[(int)parent, (int)child]);
 }