示例#1
0
 static FileMatcher()
 {
     FileMatcher.directorySeparator = new string(Path.DirectorySeparatorChar, 1);
     FileMatcher.altDirectorySeparator = new string(Path.AltDirectorySeparatorChar, 1);
     char[] chrArray = new char[] { '*', '?' };
     FileMatcher.wildcardCharacters = chrArray;
     FileMatcher.wildcardAndSemicolonCharacters = new char[] { '*', '?', ';' };
     char[] directorySeparatorChar = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };
     FileMatcher.directorySeparatorCharacters = directorySeparatorChar;
     FileMatcher.defaultGetFileSystemEntries = new FileMatcher.GetFileSystemEntries(FileMatcher.GetAccessibleFileSystemEntries);
     FileMatcher.defaultDirectoryExists = new DirectoryExists(Directory.Exists);
     FileMatcher.invalidPathChars = Path.GetInvalidPathChars();
 }
示例#2
0
        internal PrereleaseResolveNuGetPackageAssets(DirectoryExists directoryExists, FileExists fileExists, TryGetRuntimeVersion tryGetRuntimeVersion)
            : this()
        {
            if (directoryExists != null)
            {
                _directoryExists = directoryExists;
            }

            if (fileExists != null)
            {
                _fileExists = fileExists;
            }

            if (tryGetRuntimeVersion != null)
            {
                _tryGetRuntimeVersion = tryGetRuntimeVersion;
            }
        }
        internal PrereleaseResolveNuGetPackageAssets(DirectoryExists directoryExists, FileExists fileExists, TryGetRuntimeVersion tryGetRuntimeVersion)
            : this()
        {
            if (directoryExists != null)
            {
                _directoryExists = directoryExists;
            }

            if (fileExists != null)
            {
                _fileExists = fileExists;
            }

            if (tryGetRuntimeVersion != null)
            {
                _tryGetRuntimeVersion = tryGetRuntimeVersion;
            }
        }
        internal PrereleaseResolveNuGetPackageAssets(DirectoryExists directoryExists, FileExists fileExists, TryGetRuntimeVersion tryGetRuntimeVersion)
            : this()
        {
            if (directoryExists != null)
            {
                _directoryExists = directoryExists;
            }

            if (fileExists != null)
            {
                _fileExists = fileExists;
            }

            if (tryGetRuntimeVersion != null)
            {
                _tryGetRuntimeVersion = tryGetRuntimeVersion;
            }

            _reportExceptionsToMSBuildLogger = false;
        }
        internal PrereleaseResolveNuGetPackageAssets(DirectoryExists directoryExists, FileExists fileExists, TryGetRuntimeVersion tryGetRuntimeVersion)
            : this()
        {
            if (directoryExists != null)
            {
                _directoryExists = directoryExists;
            }

            if (fileExists != null)
            {
                _fileExists = fileExists;
            }

            if (tryGetRuntimeVersion != null)
            {
                _tryGetRuntimeVersion = tryGetRuntimeVersion;
            }

            _reportExceptionsToMSBuildLogger = false;
        }
        /// <summary>
        /// Heuristic that first considers the current runtime path and then searches the base of that path for the given
        /// frameworks version.
        /// </summary>
        /// <param name="currentRuntimePath">The path to the runtime that is currently executing.</param>
        /// <param name="prefix">Should be something like 'v1.2' that indicates the runtime version we want.</param>
        /// <param name="directoryExists">Delegate to method that can check for the existence of a file.</param>
        /// <param name="getDirectories">Delegate to method that can return filesystem entries.</param>
        /// <param name="architecture">.NET framework architecture</param>
        /// <returns>Will return 'null' if there is no target frameworks on this machine.</returns>
        internal static string FindDotNetFrameworkPath
        (
            string currentRuntimePath,
            string prefix,
            DirectoryExists directoryExists,
            GetDirectories getDirectories,
            DotNetFrameworkArchitecture architecture
        )
        {
            // If the COMPLUS variables are set, they override everything -- that's the directory we want.  
            string complusInstallRoot = Environment.GetEnvironmentVariable("COMPLUS_INSTALLROOT");
            string complusVersion = Environment.GetEnvironmentVariable("COMPLUS_VERSION");

            if (!String.IsNullOrEmpty(complusInstallRoot) && !String.IsNullOrEmpty(complusVersion))
            {
                return Path.Combine(complusInstallRoot, complusVersion);
            }

            // If the current runtime starts with correct prefix, then this is the runtime we want to use.
            // However, only if we're requesting current architecture -- otherwise, the base path may be different, so we'll need to look it up. 
            string leaf = Path.GetFileName(currentRuntimePath);
            if (leaf.StartsWith(prefix, StringComparison.Ordinal) && architecture == DotNetFrameworkArchitecture.Current)
            {
                return currentRuntimePath;
            }

            // We haven't managed to use exact methods to locate the FX, so
            // search for the correct path with a heuristic.
            string baseLocation = Path.GetDirectoryName(currentRuntimePath);
            string searchPattern = prefix + "*";

            int indexOfFramework64 = baseLocation.IndexOf("Framework64", StringComparison.OrdinalIgnoreCase);

            if (indexOfFramework64 != -1 && architecture == DotNetFrameworkArchitecture.Bitness32)
            {
                // need to get rid of just the 64, but want to look up 'Framework64' rather than '64' to avoid the case where 
                // the path is something like 'C:\MyPath\64\Framework64'.  9 = length of 'Framework', to make the index match 
                // the location of the '64'. 
                int indexOf64 = indexOfFramework64 + 9;
                string tempLocation = baseLocation;
                baseLocation = tempLocation.Substring(0, indexOf64) + tempLocation.Substring(indexOf64 + 2, tempLocation.Length - indexOf64 - 2);
            }
            else if (indexOfFramework64 == -1 && architecture == DotNetFrameworkArchitecture.Bitness64)
            {
                // need to add 64 -- since this is a heuristic, we assume that we just need to append.  
                baseLocation = baseLocation + "64";
            }
            // we don't need to do anything if it's DotNetFrameworkArchitecture.Current.  

            string[] directories;

            if (directoryExists(baseLocation))
            {
                directories = getDirectories(baseLocation, searchPattern);
            }
            else
            {
                // If we can't even find the base path, might as well give up now. 
                return null;
            }

            if (directories.Length == 0)
            {
                // Couldn't find the path, return a null.
                return null;
            }

            // We don't care which one we choose, but we want to be predictible.
            // The intention here is to choose the alphabetical maximum.
            string max = directories[0];

            // the max.EndsWith condition: pre beta 2 versions of v3.5 have build number like v3.5.20111.  
            // This was removed in beta2
            // We should favor \v3.5 over \v3.5.xxxxx
            // versions previous to 2.0 have .xxxx version numbers.  3.0 and 3.5 do not.
            if (!max.EndsWith(prefix, StringComparison.OrdinalIgnoreCase))
            {
                for (int i = 1; i < directories.Length; ++i)
                {
                    if (directories[i].EndsWith(prefix, StringComparison.OrdinalIgnoreCase))
                    {
                        max = directories[i];
                        break;
                    }
                    else if (String.Compare(directories[i], max, StringComparison.OrdinalIgnoreCase) > 0)
                    {
                        max = directories[i];
                    }
                }
            }

            return max;
        }
示例#7
0
 public DirectoryExists CacheDelegate(DirectoryExists directoryExistsValue)
 {
     directoryExists = directoryExistsValue;
     return(DirectoryExists);
 }
        /// <summary>
        /// Execute the task.
        /// </summary>
        /// <param name="fileExists">Delegate used for checking for the existence of a file.</param>
        /// <param name="directoryExists">Delegate used for checking for the existence of a directory.</param>
        /// <param name="getDirectories">Delegate used for finding directories.</param>
        /// <param name="getAssemblyName">Delegate used for finding fusion names of assemblyFiles.</param>
        /// <param name="getAssemblyMetadata">Delegate used for finding dependencies of a file.</param>
        /// <param name="getRegistrySubKeyNames">Used to get registry subkey names.</param>
        /// <param name="getRegistrySubKeyDefaultValue">Used to get registry default values.</param>
        /// <param name="getLastWriteTime">Delegate used to get the last write time.</param>
        /// <returns>True if there was success.</returns>
        internal bool Execute
        (
            FileExists fileExists,
            DirectoryExists directoryExists,
            GetDirectories getDirectories,
            GetAssemblyName getAssemblyName,
            GetAssemblyMetadata getAssemblyMetadata,
            GetRegistrySubKeyNames getRegistrySubKeyNames,
            GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue,
            GetLastWriteTime getLastWriteTime,
            GetAssemblyRuntimeVersion getRuntimeVersion,
            OpenBaseKey openBaseKey,
            GetAssemblyPathInGac getAssemblyPathInGac,
            IsWinMDFile isWinMDFile,
            ReadMachineTypeFromPEHeader readMachineTypeFromPEHeader
        )
        {
            bool success = true;
#if (!STANDALONEBUILD)
            using (new CodeMarkerStartEnd(CodeMarkerEvent.perfMSBuildResolveAssemblyReferenceBegin, CodeMarkerEvent.perfMSBuildResolveAssemblyReferenceEnd))
#endif
            {
                try
                {
                    FrameworkNameVersioning frameworkMoniker = null;
                    if (!String.IsNullOrEmpty(_targetedFrameworkMoniker))
                    {
                        try
                        {
                            frameworkMoniker = new FrameworkNameVersioning(_targetedFrameworkMoniker);
                        }
                        catch (ArgumentException)
                        {
                            // The exception doesn't contain the bad value, so log it ourselves
                            Log.LogErrorWithCodeFromResources("ResolveAssemblyReference.InvalidParameter", "TargetFrameworkMoniker", _targetedFrameworkMoniker, String.Empty);
                            return false;
                        }
                    }

                    Version targetedRuntimeVersion = SetTargetedRuntimeVersion(_targetedRuntimeVersionRawValue);

                    // Log task inputs.
                    LogInputs();

                    if (!VerifyInputConditions())
                    {
                        return false;
                    }

                    _logVerboseSearchResults = Environment.GetEnvironmentVariable("MSBUILDLOGVERBOSERARSEARCHRESULTS") != null;

                    // Loop through all the target framework directories that were passed in,
                    // and ensure that they all have a trailing slash.  This is necessary
                    // for the string comparisons we will do later on.
                    if (_targetFrameworkDirectories != null)
                    {
                        for (int i = 0; i < _targetFrameworkDirectories.Length; i++)
                        {
                            _targetFrameworkDirectories[i] = FileUtilities.EnsureTrailingSlash(_targetFrameworkDirectories[i]);
                        }
                    }


                    // Validate the contents of the InstalledAssemblyTables parameter.
                    AssemblyTableInfo[] installedAssemblyTableInfo = GetInstalledAssemblyTableInfo(_ignoreDefaultInstalledAssemblyTables, _installedAssemblyTables, new GetListPath(RedistList.GetRedistListPathsFromDisk), TargetFrameworkDirectories);
                    AssemblyTableInfo[] whiteListSubsetTableInfo = null;

                    InstalledAssemblies installedAssemblies = null;
                    RedistList redistList = null;

                    if (installedAssemblyTableInfo != null && installedAssemblyTableInfo.Length > 0)
                    {
                        redistList = RedistList.GetRedistList(installedAssemblyTableInfo);
                    }

                    Hashtable blackList = null;

                    // The name of the subset if it is generated or the name of the profile. This will be used for error messages and logging.
                    string subsetOrProfileName = null;

                    // Are we targeting a profile
                    bool targetingProfile = !String.IsNullOrEmpty(ProfileName) && ((FullFrameworkFolders.Length > 0) || (FullFrameworkAssemblyTables.Length > 0));
                    bool targetingSubset = false;
                    List<Exception> whiteListErrors = new List<Exception>();
                    List<string> whiteListErrorFilesNames = new List<string>();

                    // Check for partial success in GetRedistList and log any tolerated exceptions.
                    if (redistList != null && redistList.Count > 0 || targetingProfile || ShouldUseSubsetBlackList())
                    {
                        // If we are not targeting a dev 10 profile and we have the required components to generate a orcas style subset, do so
                        if (!targetingProfile && ShouldUseSubsetBlackList())
                        {
                            // Based in the target framework subset names find the paths to the files
                            SubsetListFinder whiteList = new SubsetListFinder(_targetFrameworkSubsets);
                            whiteListSubsetTableInfo = GetInstalledAssemblyTableInfo(IgnoreDefaultInstalledAssemblySubsetTables, InstalledAssemblySubsetTables, new GetListPath(whiteList.GetSubsetListPathsFromDisk), TargetFrameworkDirectories);
                            if (whiteListSubsetTableInfo.Length > 0 && (redistList != null && redistList.Count > 0))
                            {
                                blackList = redistList.GenerateBlackList(whiteListSubsetTableInfo, whiteListErrors, whiteListErrorFilesNames);
                            }
                            else
                            {
                                Log.LogWarningWithCodeFromResources("ResolveAssemblyReference.NoSubsetsFound");
                            }

                            // Could get into this situation if the redist list files were full of junk and no assemblies were read in.
                            if (blackList == null)
                            {
                                Log.LogWarningWithCodeFromResources("ResolveAssemblyReference.NoRedistAssembliesToGenerateExclusionList");
                            }

                            subsetOrProfileName = GenerateSubSetName(_targetFrameworkSubsets, _installedAssemblySubsetTables);
                            targetingSubset = true;
                        }
                        else
                        {
                            // We are targeting a profile
                            if (targetingProfile)
                            {
                                // When targeting a profile we want the redist list to be the full framework redist list, since this is what should be used
                                // when unifying assemblies ect. 
                                AssemblyTableInfo[] fullRedistAssemblyTableInfo = null;
                                RedistList fullFrameworkRedistList = null;

                                HandleProfile(installedAssemblyTableInfo /*This is the table info related to the profile*/, out fullRedistAssemblyTableInfo, out blackList, out fullFrameworkRedistList);

                                // Make sure the redist list and the installedAsemblyTableInfo structures point to the full framework, we replace the installedAssemblyTableInfo
                                // which contained the information about the profile redist files with the one from the full framework because when doing anything with the RAR cache
                                // we want to use the full frameworks redist list. Essentailly after generating the exclusion list the job of the profile redist list is done.
                                redistList = fullFrameworkRedistList;

                                // Save the profile redist list file locations as the whiteList
                                whiteListSubsetTableInfo = installedAssemblyTableInfo;

                                // Set the installed assembly table to the full redist list values
                                installedAssemblyTableInfo = fullRedistAssemblyTableInfo;
                                subsetOrProfileName = _profileName;
                            }
                        }

                        if (redistList != null && redistList.Count > 0)
                        {
                            installedAssemblies = new InstalledAssemblies(redistList);
                        }
                    }

                    // Print out any errors reading the redist list.
                    if (redistList != null)
                    {
                        // Some files may have been skipped. Log warnings for these.
                        for (int i = 0; i < redistList.Errors.Length; ++i)
                        {
                            Exception e = redistList.Errors[i];
                            string filename = redistList.ErrorFileNames[i];

                            // Give the user a warning about the bad file (or files).
                            Log.LogWarningWithCodeFromResources("ResolveAssemblyReference.InvalidInstalledAssemblyTablesFile", filename, RedistList.RedistListFolder, e.Message);
                        }

                        // Some files may have been skipped. Log warnings for these.
                        for (int i = 0; i < whiteListErrors.Count; ++i)
                        {
                            Exception e = whiteListErrors[i];
                            string filename = whiteListErrorFilesNames[i];

                            // Give the user a warning about the bad file (or files).
                            Log.LogWarningWithCodeFromResources("ResolveAssemblyReference.InvalidInstalledAssemblySubsetTablesFile", filename, SubsetListFinder.SubsetListFolder, e.Message);
                        }
                    }

                    // Load any prior saved state.
                    ReadStateFile();
                    _cache.SetGetLastWriteTime(getLastWriteTime);
                    _cache.SetInstalledAssemblyInformation(installedAssemblyTableInfo);

                    // Cache delegates.
                    getAssemblyName = _cache.CacheDelegate(getAssemblyName);
                    getAssemblyMetadata = _cache.CacheDelegate(getAssemblyMetadata);
                    fileExists = _cache.CacheDelegate(fileExists);
                    getDirectories = _cache.CacheDelegate(getDirectories);
                    getRuntimeVersion = _cache.CacheDelegate(getRuntimeVersion);

                    _projectTargetFramework = FrameworkVersionFromString(_projectTargetFrameworkAsString);

                    // Filter out all Assemblies that have SubType!='', or higher framework
                    FilterBySubtypeAndTargetFramework();

                    // Compute the set of bindingRedirect remappings.
                    DependentAssembly[] appConfigRemappedAssemblies = null;
                    if (FindDependencies)
                    {
                        try
                        {
                            appConfigRemappedAssemblies = GetAssemblyRemappingsFromAppConfig();
                        }
                        catch (AppConfigException e)
                        {
                            Log.LogErrorWithCodeFromResources(null, e.FileName, e.Line, e.Column, 0, 0, "ResolveAssemblyReference.InvalidAppConfig", AppConfigFile, e.Message);
                            return false;
                        }
                    }

                    SystemProcessorArchitecture processorArchitecture = TargetProcessorArchitectureToEnumeration(_targetProcessorArchitecture);

                    // Start the table of dependencies with all of the primary references.
                    ReferenceTable dependencyTable = new ReferenceTable
                    (
                        BuildEngine,
                        _findDependencies,
                        _findSatellites,
                        _findSerializationAssemblies,
                        _findRelatedFiles,
                        _searchPaths,
                        _allowedAssemblyExtensions,
                        _relatedFileExtensions,
                        _candidateAssemblyFiles,
                        _resolvedSDKReferences,
                        _targetFrameworkDirectories,
                        installedAssemblies,
                        processorArchitecture,
                        fileExists,
                        directoryExists,
                        getDirectories,
                        getAssemblyName,
                        getAssemblyMetadata,
                        getRegistrySubKeyNames,
                        getRegistrySubKeyDefaultValue,
                        openBaseKey,
                        getRuntimeVersion,
                        targetedRuntimeVersion,
                        _projectTargetFramework,
                        frameworkMoniker,
                        Log,
                        _latestTargetFrameworkDirectories,
                        _copyLocalDependenciesWhenParentReferenceInGac,
                        DoNotCopyLocalIfInGac,
                        getAssemblyPathInGac,
                        isWinMDFile,
                        _ignoreVersionForFrameworkReferences,
                        readMachineTypeFromPEHeader,
                        _warnOrErrorOnTargetArchitectureMismatch,
                        _ignoreTargetFrameworkAttributeVersionMismatch,
                        _unresolveFrameworkAssembliesFromHigherFrameworks
                        );

                    // If AutoUnify, then compute the set of assembly remappings.
                    ArrayList generalResolutionExceptions = new ArrayList();

                    subsetOrProfileName = targetingSubset && String.IsNullOrEmpty(_targetedFrameworkMoniker) ? subsetOrProfileName : _targetedFrameworkMoniker;
                    bool excludedReferencesExist = false;

                    DependentAssembly[] autoUnifiedRemappedAssemblies = null;
                    AssemblyNameReference[] autoUnifiedRemappedAssemblyReferences = null;
                    if (AutoUnify && FindDependencies)
                    {
                        // Compute all dependencies.
                        dependencyTable.ComputeClosure
                        (
                            // Use any app.config specified binding redirects so that later when we output suggested redirects
                            // for the GenerateBindingRedirects target, we don't suggest ones that the user already wrote
                            appConfigRemappedAssemblies,
                            _assemblyFiles,
                            _assemblyNames,
                            generalResolutionExceptions
                        );

                        try
                        {
                            excludedReferencesExist = false;
                            if (redistList != null && redistList.Count > 0)
                            {
                                excludedReferencesExist = dependencyTable.MarkReferencesForExclusion(blackList);
                            }
                        }
                        catch (InvalidOperationException e)
                        {
                            Log.LogErrorWithCodeFromResources("ResolveAssemblyReference.ProblemDeterminingFrameworkMembership", e.Message);
                            return false;
                        }

                        if (excludedReferencesExist)
                        {
                            dependencyTable.RemoveReferencesMarkedForExclusion(true /* Remove the reference and do not warn*/, subsetOrProfileName);
                        }


                        // Based on the closure, get a table of ideal remappings needed to 
                        // produce zero conflicts.
                        dependencyTable.ResolveConflicts
                        (
                            out autoUnifiedRemappedAssemblies,
                            out autoUnifiedRemappedAssemblyReferences
                        );
                    }

                    DependentAssembly[] allRemappedAssemblies = CombineRemappedAssemblies(appConfigRemappedAssemblies, autoUnifiedRemappedAssemblies);

                    // Compute all dependencies.
                    dependencyTable.ComputeClosure(allRemappedAssemblies, _assemblyFiles, _assemblyNames, generalResolutionExceptions);

                    try
                    {
                        excludedReferencesExist = false;
                        if (redistList != null && redistList.Count > 0)
                        {
                            excludedReferencesExist = dependencyTable.MarkReferencesForExclusion(blackList);
                        }
                    }
                    catch (InvalidOperationException e)
                    {
                        Log.LogErrorWithCodeFromResources("ResolveAssemblyReference.ProblemDeterminingFrameworkMembership", e.Message);
                        return false;
                    }

                    if (excludedReferencesExist)
                    {
                        dependencyTable.RemoveReferencesMarkedForExclusion(false /* Remove the reference and warn*/, subsetOrProfileName);
                    }

                    // Resolve any conflicts.
                    DependentAssembly[] idealAssemblyRemappings = null;
                    AssemblyNameReference[] idealAssemblyRemappingsIdentities = null;

                    dependencyTable.ResolveConflicts
                    (
                        out idealAssemblyRemappings,
                        out idealAssemblyRemappingsIdentities
                    );

                    // Build the output tables.
                    dependencyTable.GetReferenceItems
                    (
                        out _resolvedFiles,
                        out _resolvedDependencyFiles,
                        out _relatedFiles,
                        out _satelliteFiles,
                        out _serializationAssemblyFiles,
                        out _scatterFiles,
                        out _copyLocalFiles
                    );

                    // If we're not finding dependencies, then don't suggest redirects (they're only about dependencies).
                    if (FindDependencies)
                    {
                        // Build the table of suggested redirects. If we're auto-unifying, we want to output all the 
                        // assemblies that we auto-unified so that GenerateBindingRedirects can consume them, 
                        // not just the required ones for build to succeed
                        DependentAssembly[] remappings = AutoUnify ? autoUnifiedRemappedAssemblies : idealAssemblyRemappings;
                        AssemblyNameReference[] remappedReferences = AutoUnify ? autoUnifiedRemappedAssemblyReferences : idealAssemblyRemappingsIdentities;
                        PopulateSuggestedRedirects(remappings, remappedReferences);
                    }

                    bool useSystemRuntime = false;
                    foreach (var reference in dependencyTable.References.Keys)
                    {
                        if (string.Equals(SystemRuntimeAssemblyName, reference.Name, StringComparison.OrdinalIgnoreCase))
                        {
                            useSystemRuntime = true;
                            break;
                        }
                    }

                    if (!useSystemRuntime && !FindDependencies)
                    {
                        // when we are not producing the dependency graph look for direct dependencies of primary references.
                        foreach (var resolvedReference in dependencyTable.References.Values)
                        {
                            var rawDependencies = GetDependencies(resolvedReference, fileExists, getAssemblyMetadata);
                            if (rawDependencies != null)
                            {
                                foreach (var dependentReference in rawDependencies)
                                {
                                    if (string.Equals(SystemRuntimeAssemblyName, dependentReference.Name, StringComparison.OrdinalIgnoreCase))
                                    {
                                        useSystemRuntime = true;
                                        break;
                                    }
                                }
                            }

                            if (useSystemRuntime)
                            {
                                break;
                            }
                        }
                    }

                    this.DependsOnSystemRuntime = useSystemRuntime.ToString();

                    WriteStateFile();

                    // Save the new state out and put into the file exists if it is actually on disk.
                    if (_stateFile != null && fileExists(_stateFile))
                    {
                        _filesWritten.Add(new TaskItem(_stateFile));
                    }

                    // Log the results.
                    success = LogResults(dependencyTable, idealAssemblyRemappings, idealAssemblyRemappingsIdentities, generalResolutionExceptions);

                    DumpTargetProfileLists(installedAssemblyTableInfo, whiteListSubsetTableInfo, dependencyTable);

                    if (processorArchitecture != SystemProcessorArchitecture.None && _warnOrErrorOnTargetArchitectureMismatch != WarnOrErrorOnTargetArchitectureMismatchBehavior.None)
                    {
                        foreach (ITaskItem item in _resolvedFiles)
                        {
                            AssemblyNameExtension assemblyName = null;

                            if (fileExists(item.ItemSpec) && !Reference.IsFrameworkFile(item.ItemSpec, _targetFrameworkDirectories))
                            {
                                try
                                {
                                    assemblyName = getAssemblyName(item.ItemSpec);
                                }
                                catch (System.IO.FileLoadException)
                                {
                                    // Its pretty hard to get here, you need an assembly that contains a valid reference
                                    // to a dependent assembly that, in turn, throws a FileLoadException during GetAssemblyName.
                                    // Still it happened once, with an older version of the CLR. 

                                    // ...falling through and relying on the targetAssemblyName==null behavior below...
                                }
                                catch (System.IO.FileNotFoundException)
                                {
                                    // Its pretty hard to get here, also since we do a file existence check right before calling this method so it can only happen if the file got deleted between that check and this call.
                                }
                                catch (UnauthorizedAccessException)
                                {
                                }
                                catch (BadImageFormatException)
                                {
                                }
                            }

                            if (assemblyName != null)
                            {
                                SystemProcessorArchitecture assemblyArch = assemblyName.ProcessorArchitecture;

                                // If the assembly is MSIL or none it can work anywhere so there does not need to be any warning ect.
                                if (assemblyArch == SystemProcessorArchitecture.MSIL || assemblyArch == SystemProcessorArchitecture.None)
                                {
                                    continue;
                                }

                                if (processorArchitecture != assemblyArch)
                                {
                                    if (_warnOrErrorOnTargetArchitectureMismatch == WarnOrErrorOnTargetArchitectureMismatchBehavior.Error)
                                    {
                                        Log.LogErrorWithCodeFromResources("ResolveAssemblyReference.MismatchBetweenTargetedAndReferencedArch", ProcessorArchitectureToString(processorArchitecture), item.GetMetadata("OriginalItemSpec"), ProcessorArchitectureToString(assemblyArch));
                                    }
                                    else
                                    {
                                        Log.LogWarningWithCodeFromResources("ResolveAssemblyReference.MismatchBetweenTargetedAndReferencedArch", ProcessorArchitectureToString(processorArchitecture), item.GetMetadata("OriginalItemSpec"), ProcessorArchitectureToString(assemblyArch));
                                    }
                                }
                            }
                        }
                    }
                    return success && !Log.HasLoggedErrors;
                }
                catch (ArgumentException e)
                {
                    Log.LogErrorWithCodeFromResources("General.InvalidArgument", e.Message);
                }

                // InvalidParameterValueException is thrown inside RAR when we find a specific parameter
                // has an invalid value. It's then caught up here so that we can abort the task.
                catch (InvalidParameterValueException e)
                {
                    Log.LogErrorWithCodeFromResources(null, "", 0, 0, 0, 0,
                        "ResolveAssemblyReference.InvalidParameter", e.ParamName, e.ActualValue, e.Message);
                }
            }

            return success && !Log.HasLoggedErrors;
        }
示例#9
0
        /// <summary>
        /// Additional constructor to make unit testing the TaskRegistry support easier
        /// </summary>
        /// <remarks>
        /// Internal for unit test purposes only.
        /// </remarks>
        /// <param name="toolsVersion">Name of the toolset</param>
        /// <param name="toolsPath">Path to this toolset's tasks and targets</param>
        /// <param name="buildProperties">
        /// Properties that should be associated with the Toolset.
        /// May be null, in which case an empty property group will be used.
        /// </param>
        /// <param name="projectCollection">The project collection.</param>
        /// <param name="getFiles">A delegate to intercept GetFiles calls.  For unit testing.</param>
        /// <param name="loadXmlFromPath">A delegate to intercept Xml load calls.  For unit testing.</param>
        internal Toolset(string toolsVersion, string toolsPath, PropertyDictionary<ProjectPropertyInstance> buildProperties, ProjectCollection projectCollection, DirectoryGetFiles getFiles, LoadXmlFromPath loadXmlFromPath, string msbuildOverrideTasksPath, DirectoryExists directoryExists)
            : this(toolsVersion, toolsPath, buildProperties, projectCollection.EnvironmentProperties, projectCollection.GlobalPropertiesCollection, null, msbuildOverrideTasksPath, null)
        {
            ErrorUtilities.VerifyThrowInternalNull(getFiles, "getFiles");
            ErrorUtilities.VerifyThrowInternalNull(loadXmlFromPath, "loadXmlFromPath");

            _directoryExists = directoryExists;
            _getFiles = getFiles;
            _loadXmlFromPath = loadXmlFromPath;
        }
示例#10
0
        /// <summary>
        /// Given a filespec, find the files that match. 
        /// Will never throw IO exceptions: if there is no match, returns the input verbatim.
        /// </summary>
        /// <param name="projectDirectoryUnescaped">The project directory.</param>
        /// <param name="filespecUnescaped">Get files that match the given file spec.</param>
        /// <param name="getFileSystemEntries">Get files that match the given file spec.</param>
        /// <param name="directoryExists">Determine whether a directory exists.</param>
        /// <returns>The array of files.</returns>
        internal static string[] GetFiles
        (
            string projectDirectoryUnescaped,
            string filespecUnescaped,
            GetFileSystemEntries getFileSystemEntries,
            DirectoryExists directoryExists
        )
        {
            // For performance. Short-circuit iff there is no wildcard.
            // Perf Note: Doing a [Last]IndexOfAny(...) is much faster than compiling a
            // regular expression that does the same thing, regardless of whether
            // filespec contains one of the characters.
            // Choose LastIndexOfAny instead of IndexOfAny because it seems more likely
            // that wildcards will tend to be towards the right side.
            if (!HasWildcards(filespecUnescaped))
            {
                return new string[] { filespecUnescaped };
            }

            // UNDONE (perf): Short circuit the complex processing when we only have a path and a wildcarded filename

            /*
             * Even though we return a string[] we work internally with an IList.
             * This is because it's cheaper to add items to an IList and this code
             * might potentially do a lot of that.
             */
            System.Collections.ArrayList arrayListOfFiles = new System.Collections.ArrayList();
            System.Collections.IList listOfFiles = (System.Collections.IList)arrayListOfFiles;

            /*
             * Analyze the file spec and get the information we need to do the matching.
             */
            string fixedDirectoryPart;
            string wildcardDirectoryPart;
            string filenamePart;
            string matchFileExpression;
            bool needsRecursion;
            bool isLegalFileSpec;
            GetFileSpecInfo
            (
                filespecUnescaped,
                out fixedDirectoryPart,
                out wildcardDirectoryPart,
                out filenamePart,
                out matchFileExpression,
                out needsRecursion,
                out isLegalFileSpec,
                getFileSystemEntries
            );

            /*
             * If the filespec is invalid, then just return now.
             */
            if (!isLegalFileSpec)
            {
                return new string[] { filespecUnescaped };
            }

            // The projectDirectory is not null only if we are running the evaluation from
            // inside the engine (i.e. not from a task)
            bool stripProjectDirectory = false;
            if (projectDirectoryUnescaped != null)
            {
                if (fixedDirectoryPart != null)
                {
                    string oldFixedDirectoryPart = fixedDirectoryPart;
                    try
                    {
                        fixedDirectoryPart = Path.Combine(projectDirectoryUnescaped, fixedDirectoryPart);
                    }
                    catch (ArgumentException)
                    {
                        return new string[0];
                    }

                    stripProjectDirectory = !String.Equals(fixedDirectoryPart, oldFixedDirectoryPart, StringComparison.OrdinalIgnoreCase);
                }
                else
                {
                    fixedDirectoryPart = projectDirectoryUnescaped;
                    stripProjectDirectory = true;
                }
            }

            /*
             * If the fixed directory part doesn't exist, then this means no files should be
             * returned.
             */
            if (fixedDirectoryPart.Length > 0 && !directoryExists(fixedDirectoryPart))
            {
                return new string[0];
            }

            // determine if we need to use the regular expression to match the files
            // PERF NOTE: Constructing a Regex object is expensive, so we avoid it whenever possible
            bool matchWithRegex =
                // if we have a directory specification that uses wildcards, and
                (wildcardDirectoryPart.Length > 0) &&
                // the specification is not a simple "**"
                (wildcardDirectoryPart != (recursiveDirectoryMatch + s_directorySeparator));
            // then we need to use the regular expression

            // if we're not using the regular expression, get the file pattern extension
            string extensionPart = matchWithRegex
                ? null
                : Path.GetExtension(filenamePart);

            // check if the file pattern would cause Windows to match more loosely on the extension
            // NOTE: Windows matches loosely in two cases (in the absence of the * wildcard in the extension):
            // 1) if the extension ends with the ? wildcard, it matches files with shorter extensions also e.g. "file.tx?" would
            //    match both "file.txt" and "file.tx"
            // 2) if the extension is three characters, and the filename contains the * wildcard, it matches files with longer
            //    extensions that start with the same three characters e.g. "*.htm" would match both "file.htm" and "file.html"
            bool needToEnforceExtensionLength =
                    (extensionPart != null) &&
                    (extensionPart.IndexOf('*') == -1)
                &&
                    (extensionPart.EndsWith("?", StringComparison.Ordinal)
                ||
                    ((extensionPart.Length == (3 + 1 /* +1 for the period */)) &&
                    (filenamePart.IndexOf('*') != -1)));

            /*
             * Now get the files that match, starting at the lowest fixed directory.
             */
            try
            {
                GetFilesRecursive(listOfFiles, fixedDirectoryPart, wildcardDirectoryPart,
                    // if using the regular expression, ignore the file pattern
                    (matchWithRegex ? null : filenamePart), (needToEnforceExtensionLength ? extensionPart.Length : 0),
                    // if using the file pattern, ignore the regular expression
                    (matchWithRegex ? new Regex(matchFileExpression, RegexOptions.IgnoreCase) : null),
                    needsRecursion, projectDirectoryUnescaped, stripProjectDirectory, getFileSystemEntries);
            }
            catch (Exception ex) when (ExceptionHandling.IsIoRelatedException(ex))
            {
                // Assume it's not meant to be a path
                return new[] { filespecUnescaped };
            }

            /*
             * Build the return array.
             */
            string[] files = (string[])arrayListOfFiles.ToArray(typeof(string));
            return files;
        }
示例#11
0
        internal static string FindDotNetFrameworkPath(string currentRuntimePath, string prefix, string frameworkVersion, DirectoryExists directoryExists, GetDirectories getDirectories, DotNetFrameworkArchitecture architecture, bool useHeuristic)
        {
            string[] strArray;
            if (Path.GetFileName(currentRuntimePath).StartsWith(prefix, StringComparison.Ordinal) && (architecture == DotNetFrameworkArchitecture.Current))
            {
                return(currentRuntimePath);
            }
            string str2 = null;

            if (architecture == DotNetFrameworkArchitecture.Current)
            {
                str2 = ConstructDotNetFrameworkPathFromRuntimeInfo(frameworkVersion);
            }
            if ((str2 != null) || !useHeuristic)
            {
                return(str2);
            }
            string directoryName = Path.GetDirectoryName(currentRuntimePath);
            string pattern       = prefix + "*";

            if (directoryName.Contains("64") && (architecture == DotNetFrameworkArchitecture.Bitness32))
            {
                int    index = directoryName.IndexOf("64", StringComparison.OrdinalIgnoreCase);
                string str5  = directoryName;
                directoryName = str5.Substring(0, index) + str5.Substring(index + 2, (str5.Length - index) - 2);
            }
            else if (!directoryName.Contains("64") && (architecture == DotNetFrameworkArchitecture.Bitness64))
            {
                directoryName = directoryName + "64";
            }
            if (directoryExists(directoryName))
            {
                strArray = getDirectories(directoryName, pattern);
            }
            else
            {
                return(null);
            }
            if (strArray.Length == 0)
            {
                return(null);
            }
            string strB = strArray[0];

            if (!strB.EndsWith(prefix, StringComparison.OrdinalIgnoreCase))
            {
                for (int i = 1; i < strArray.Length; i++)
                {
                    if (strArray[i].EndsWith(prefix, StringComparison.OrdinalIgnoreCase))
                    {
                        return(strArray[i]);
                    }
                    if (string.Compare(strArray[i], strB, StringComparison.OrdinalIgnoreCase) > 0)
                    {
                        strB = strArray[i];
                    }
                }
            }
            return(strB);
        }
示例#12
0
        /// <summary>
        /// Given a filespec, find the files that match. 
        /// Will never throw IO exceptions: if there is no match, returns the input verbatim.
        /// </summary>
        /// <param name="projectDirectoryUnescaped">The project directory.</param>
        /// <param name="filespecUnescaped">Get files that match the given file spec.</param>
        /// <param name="getFileSystemEntries">Get files that match the given file spec.</param>
        /// <param name="directoryExists">Determine whether a directory exists.</param>
        /// <returns>The array of files.</returns>
        internal static string[] GetFiles
        (
            string projectDirectoryUnescaped,
            string filespecUnescaped,
            IEnumerable<string> excludeSpecsUnescaped,
            GetFileSystemEntries getFileSystemEntries,
            DirectoryExists directoryExists
        )
        {
            // For performance. Short-circuit iff there is no wildcard.
            // Perf Note: Doing a [Last]IndexOfAny(...) is much faster than compiling a
            // regular expression that does the same thing, regardless of whether
            // filespec contains one of the characters.
            // Choose LastIndexOfAny instead of IndexOfAny because it seems more likely
            // that wildcards will tend to be towards the right side.
            if (!HasWildcards(filespecUnescaped))
            {
                return CreateArrayWithSingleItemIfNotExcluded(filespecUnescaped, excludeSpecsUnescaped);
            }

            // UNDONE (perf): Short circuit the complex processing when we only have a path and a wildcarded filename

            /*
             * Analyze the file spec and get the information we need to do the matching.
             */
            bool stripProjectDirectory;
            RecursionState state;
            var action = GetFileSearchData(projectDirectoryUnescaped, filespecUnescaped, getFileSystemEntries, directoryExists,
                out stripProjectDirectory, out state);

            if (action == SearchAction.ReturnEmptyList)
            {
                return new string[0];
            }
            else if (action == SearchAction.ReturnFileSpec)
            {
                return CreateArrayWithSingleItemIfNotExcluded(filespecUnescaped, excludeSpecsUnescaped);
            }
            else if (action != SearchAction.RunSearch)
            {
                //  This means the enum value wasn't valid (or a new one was added without updating code correctly)
                throw new NotSupportedException(action.ToString());
            }

            List<RecursionState> searchesToExclude = null;

            //  Exclude searches which will become active when the recursive search reaches their BaseDirectory.
            //  The BaseDirectory of the exclude search is the key for this dictionary.
            Dictionary<string, List<RecursionState>> searchesToExcludeInSubdirs = null;

            HashSet<string> resultsToExclude = null;
            if (excludeSpecsUnescaped != null)
            {
                searchesToExclude = new List<RecursionState>();
                foreach (string excludeSpec in excludeSpecsUnescaped)
                {
                    //  This is ignored, we always use the include pattern's value for stripProjectDirectory
                    bool excludeStripProjectDirectory;

                    RecursionState excludeState;
                    var excludeAction = GetFileSearchData(projectDirectoryUnescaped, excludeSpec, getFileSystemEntries, directoryExists,
                        out excludeStripProjectDirectory, out excludeState);

                    if (excludeAction == SearchAction.ReturnFileSpec)
                    {
                        if (resultsToExclude == null)
                        {
                            resultsToExclude = new HashSet<string>();
                        }
                        resultsToExclude.Add(excludeSpec);
                    }
                    else if (excludeAction == SearchAction.ReturnEmptyList)
                    {
                        //  Nothing to do
                        continue;
                    }
                    else if (excludeAction != SearchAction.RunSearch)
                    {
                        //  This means the enum value wasn't valid (or a new one was added without updating code correctly)
                        throw new NotSupportedException(excludeAction.ToString());
                    }

                    var excludeBaseDirectoryNormalized = excludeState.BaseDirectory.NormalizeForPathComparison();
                    var includeBaseDirectoryNormalized = state.BaseDirectory.NormalizeForPathComparison();

                    if (excludeBaseDirectoryNormalized != includeBaseDirectoryNormalized)
                    {
                        //  What to do if the BaseDirectory for the exclude search doesn't match the one for inclusion?
                        //  - If paths don't match (one isn't a prefix of the other), then ignore the exclude search.  Examples:
                        //      - c:\Foo\ - c:\Bar\
                        //      - c:\Foo\Bar\ - C:\Foo\Baz\
                        //      - c:\Foo\ - c:\Foo2\
                        if (excludeBaseDirectoryNormalized.Length == includeBaseDirectoryNormalized.Length)
                        {
                            //  Same length, but different paths.  Ignore this exclude search
                            continue;
                        }
                        else if (excludeBaseDirectoryNormalized.Length > includeBaseDirectoryNormalized.Length)
                        {
                            if (!excludeBaseDirectoryNormalized.StartsWith(includeBaseDirectoryNormalized))
                            {
                                //  Exclude path is longer, but doesn't start with include path.  So ignore it.
                                continue;
                            }

                            //  - The exclude BaseDirectory is somewhere under the include BaseDirectory. So
                            //    keep the exclude search, but don't do any processing on it while recursing until the baseDirectory
                            //    in the recursion matches the exclude BaseDirectory.  Examples:
                            //      - Include - Exclude
                            //      - C:\git\msbuild\ - c:\git\msbuild\obj\
                            //      - C:\git\msbuild\ - c:\git\msbuild\src\Common\

                            if (searchesToExcludeInSubdirs == null)
                            {
                                searchesToExcludeInSubdirs = new Dictionary<string, List<RecursionState>>();
                            }
                            List<RecursionState> listForSubdir;
                            if (!searchesToExcludeInSubdirs.TryGetValue(excludeBaseDirectoryNormalized, out listForSubdir))
                            {
                                listForSubdir = new List<RecursionState>();

                                // The normalization fixes https://github.com/Microsoft/msbuild/issues/917
                                // and is a partial fix for https://github.com/Microsoft/msbuild/issues/724
                                searchesToExcludeInSubdirs[excludeBaseDirectoryNormalized] = listForSubdir;
                            }
                            listForSubdir.Add(excludeState);
                        }
                        else
                        {
                            //  Exclude base directory length is less than include base directory length.
                            if (!state.BaseDirectory.StartsWith(excludeState.BaseDirectory))
                            {
                                //  Include path is longer, but doesn't start with the exclude path.  So ignore exclude path
                                //  (since it won't match anything under the include path)
                                continue;
                            }

                            //  Now check the wildcard part
                            if (excludeState.RemainingWildcardDirectory.Length == 0)
                            {
                                //  The wildcard part is empty, so ignore the exclude search, as it's looking for files non-recursively
                                //  in a folder higher up than the include baseDirectory.
                                //  Example: include="c:\git\msbuild\src\Framework\**\*.cs" exclude="c:\git\msbuild\*.cs"
                                continue;
                            }
                            else if (IsRecursiveDirectoryMatch(excludeState.RemainingWildcardDirectory))
                            {
                                //  The wildcard part is exactly "**\", so the exclude pattern will apply to everything in the include
                                //  pattern, so simply update the exclude's BaseDirectory to be the same as the include baseDirectory
                                //  Example: include="c:\git\msbuild\src\Framework\**\*.*" exclude="c:\git\msbuild\**\*.bak"
                                excludeState.BaseDirectory = state.BaseDirectory;
                                searchesToExclude.Add(excludeState);
                            }
                            else
                            {
                                //  The wildcard part is non-empty and not "**\", so we will need to match it with a Regex.  Fortunately
                                //  these conditions mean that it needs to be matched with a Regex anyway, so here we will update the
                                //  BaseDirectory to be the same as the exclude BaseDirectory, and change the wildcard part to be "**\"
                                //  because we don't know where the different parts of the exclude wildcard part would be matched.
                                //  Example: include="c:\git\msbuild\src\Framework\**\*.*" exclude="c:\git\msbuild\**\bin\**\*.*"
                                Debug.Assert(excludeState.SearchData.RegexFileMatch != null, "Expected Regex to be used for exclude file matching");
                                excludeState.BaseDirectory = state.BaseDirectory;
                                excludeState.RemainingWildcardDirectory = recursiveDirectoryMatch + s_directorySeparator;
                                searchesToExclude.Add(excludeState);
                            }
                        }
                    }
                    else
                    {
                        searchesToExclude.Add(excludeState);
                    }
                }
            }

            if (searchesToExclude != null && searchesToExclude.Count == 0)
            {
                searchesToExclude = null;
            }

            /*
             * Even though we return a string[] we work internally with an IList.
             * This is because it's cheaper to add items to an IList and this code
             * might potentially do a lot of that.
             */
            var listOfFiles = new List<string>();

            /*
             * Now get the files that match, starting at the lowest fixed directory.
             */
            try
            {
                GetFilesRecursive(
                    listOfFiles,
                    state,
                    projectDirectoryUnescaped,
                    stripProjectDirectory,
                    getFileSystemEntries,
                    searchesToExclude,
                    searchesToExcludeInSubdirs);
            }
            catch (Exception ex) when (ExceptionHandling.IsIoRelatedException(ex))
            {
                // Assume it's not meant to be a path
                return CreateArrayWithSingleItemIfNotExcluded(filespecUnescaped, excludeSpecsUnescaped);
            }

            /*
             * Build the return array.
             */
            var files = resultsToExclude != null
                ? listOfFiles.Where(f => !resultsToExclude.Contains(f)).ToArray()
                : listOfFiles.ToArray();

            return files;
        }
示例#13
0
        /// <summary>
        /// Construct.
        /// </summary>
        /// <param name="findDependencies">If true, then search for dependencies.</param>
        /// <param name="findSatellites">If true, then search for satellite files.</param>
        /// <param name="findSerializatoinAssemblies">If true, then search for serialization assembly files.</param>
        /// <param name="findRelatedFiles">If true, then search for related files.</param>
        /// <param name="searchPaths">Paths to search for dependent assemblies on.</param>
        /// <param name="candidateAssemblyFiles">List of literal assembly file names to be considered when SearchPaths has {CandidateAssemblyFiles}.</param>
        /// <param name="resolvedSDKItems">Resolved sdk items</param>
        /// <param name="frameworkPaths">Path to the FX.</param>
        /// <param name="installedAssemblies">Installed assembly XML tables.</param>
        /// <param name="targetProcessorArchitecture">Like x86 or IA64\AMD64, the processor architecture being targetted.</param>
        /// <param name="fileExists">Delegate used for checking for the existence of a file.</param>
        /// <param name="directoryExists">Delegate used for files.</param>
        /// <param name="getDirectories">Delegate used for getting directories.</param>
        /// <param name="getAssemblyName">Delegate used for getting assembly names.</param>
        /// <param name="getAssemblyMetadata">Delegate used for finding dependencies of a file.</param>
        /// <param name="getRegistrySubKeyNames">Used to get registry subkey names.</param>
        /// <param name="getRegistrySubKeyDefaultValue">Used to get registry default values.</param>
        internal ReferenceTable
        (
                      IBuildEngine buildEngine,
            bool findDependencies,
            bool findSatellites,
            bool findSerializationAssemblies,
            bool findRelatedFiles,
            string[] searchPaths,
            string[] allowedAssemblyExtensions,
            string[] relatedFileExtensions,
            string[] candidateAssemblyFiles,
            ITaskItem[] resolvedSDKItems,
            string[] frameworkPaths,
            InstalledAssemblies installedAssemblies,
            System.Reflection.ProcessorArchitecture targetProcessorArchitecture,
            FileExists fileExists,
            DirectoryExists directoryExists,
            GetDirectories getDirectories,
            GetAssemblyName getAssemblyName,
            GetAssemblyMetadata getAssemblyMetadata,
            GetRegistrySubKeyNames getRegistrySubKeyNames,
            GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue,
            OpenBaseKey openBaseKey,
            GetAssemblyRuntimeVersion getRuntimeVersion,
            Version targetedRuntimeVersion,
            Version projectTargetFramework,
            FrameworkNameVersioning targetFrameworkMoniker,
            TaskLoggingHelper log,
            string[] latestTargetFrameworkDirectories,
            bool copyLocalDependenciesWhenParentReferenceInGac,
            bool doNotCopyLocalIfInGac,
            GetAssemblyPathInGac getAssemblyPathInGac,
            IsWinMDFile isWinMDFile,
            bool ignoreVersionForFrameworkReferences,
            ReadMachineTypeFromPEHeader readMachineTypeFromPEHeader,
            WarnOrErrorOnTargetArchitectureMismatchBehavior warnOrErrorOnTargetArchitectureMismatch,
            bool ignoreFrameworkAttributeVersionMismatch,
            bool unresolveFrameworkAssembliesFromHigherFrameworks
        )
        {
            _buildEngine = buildEngine;
            _log = log;
            _findDependencies = findDependencies;
            _findSatellites = findSatellites;
            _findSerializationAssemblies = findSerializationAssemblies;
            _findRelatedFiles = findRelatedFiles;
            _frameworkPaths = frameworkPaths;
            _allowedAssemblyExtensions = allowedAssemblyExtensions;
            _relatedFileExtensions = relatedFileExtensions;
            _installedAssemblies = installedAssemblies;
            _targetProcessorArchitecture = targetProcessorArchitecture;
            _fileExists = fileExists;
            _directoryExists = directoryExists;
            _getDirectories = getDirectories;
            _getAssemblyName = getAssemblyName;
            _getAssemblyMetadata = getAssemblyMetadata;
            _getRuntimeVersion = getRuntimeVersion;
            _projectTargetFramework = projectTargetFramework;
            _targetedRuntimeVersion = targetedRuntimeVersion;
            _openBaseKey = openBaseKey;
            _targetFrameworkMoniker = targetFrameworkMoniker;
            _latestTargetFrameworkDirectories = latestTargetFrameworkDirectories;
            _copyLocalDependenciesWhenParentReferenceInGac = copyLocalDependenciesWhenParentReferenceInGac;
            _doNotCopyLocalIfInGac = doNotCopyLocalIfInGac;
            _getAssemblyPathInGac = getAssemblyPathInGac;
            _isWinMDFile = isWinMDFile;
            _readMachineTypeFromPEHeader = readMachineTypeFromPEHeader;
            _warnOrErrorOnTargetArchitectureMismatch = warnOrErrorOnTargetArchitectureMismatch;
            _ignoreFrameworkAttributeVersionMismatch = ignoreFrameworkAttributeVersionMismatch;

            // Set condition for when to check assembly version against the target framework version 
            _checkAssemblyVersionAgainstTargetFrameworkVersion = unresolveFrameworkAssembliesFromHigherFrameworks || ((_projectTargetFramework ?? ReferenceTable.s_targetFrameworkVersion_40) <= ReferenceTable.s_targetFrameworkVersion_40);

            // Convert the list of installed SDK's to a dictionary for faster lookup
            _resolvedSDKReferences = new Dictionary<string, ITaskItem>(StringComparer.OrdinalIgnoreCase);
            _ignoreVersionForFrameworkReferences = ignoreVersionForFrameworkReferences;


            if (resolvedSDKItems != null)
            {
                foreach (ITaskItem resolvedSDK in resolvedSDKItems)
                {
                    string sdkName = resolvedSDK.GetMetadata("SDKName");

                    if (sdkName.Length > 0)
                    {
                        if (!_resolvedSDKReferences.ContainsKey(sdkName))
                        {
                            _resolvedSDKReferences.Add(sdkName, resolvedSDK);
                        }
                        else
                        {
                            _resolvedSDKReferences[sdkName] = resolvedSDK;
                        }
                    }
                }
            }

            // Compile searchpaths into fast resolver array.
            _compiledSearchPaths = AssemblyResolution.CompileSearchPaths
                (
                    buildEngine,
                    searchPaths,
                    candidateAssemblyFiles,
                    targetProcessorArchitecture,
                    frameworkPaths,
                    fileExists,
                    getAssemblyName,
                    getRegistrySubKeyNames,
                    getRegistrySubKeyDefaultValue,
                    openBaseKey,
                    installedAssemblies,
                    getRuntimeVersion,
                    targetedRuntimeVersion,
                    getAssemblyPathInGac
                );
        }
示例#14
0
        public static string[] SplitedString; // The Splited String
        public static void ReadAsync(string Command)
        {
            SplitedString = Command.Split(' '); // The Splited String

            // Format the current Taiyou Line
            for (int i = 0; i < SplitedString.Length; i++)
            {
                // FORMATATION
                SplitedString[i] = SplitedString[i].Replace("%N", Environment.NewLine); // New Line

                for (int i2 = 0; i2 < GlobalVars_String_Names.Count; i2++)
                {
                    SplitedString[i] = SplitedString[i].Replace("$STRING_" + GlobalVars_String_Names[i2] + "$", GlobalVars_String_Content[i2].Replace(" ", ""));
                }
                for (int i2 = 0; i2 < GlobalVars_Bool_Names.Count; i2++)
                {
                    SplitedString[i] = SplitedString[i].Replace("$BOOL_" + GlobalVars_Bool_Names[i2] + "$", Convert.ToString(GlobalVars_Bool_Content[i2]));
                }
                for (int i2 = 0; i2 < GlobalVars_Int_Names.Count; i2++)
                {
                    SplitedString[i] = SplitedString[i].Replace("$INT_" + GlobalVars_Int_Names[i2] + "$", Convert.ToString(GlobalVars_Int_Content[i2]));
                }
                for (int i2 = 0; i2 < GlobalVars_Float_Names.Count; i2++)
                {
                    SplitedString[i] = SplitedString[i].Replace("$FLOAT_" + GlobalVars_Float_Names[i2] + "$", Convert.ToString(GlobalVars_Float_Content[i2]));
                }



                if (SplitedString[i].Contains("%RANDOM%"))
                {
                    string[] SubSplitedString = SplitedString[i].Split('%');
                    string   Arg1             = SubSplitedString[2]; // Number 1
                    string   Arg2             = SubSplitedString[3]; // Number 2
                    Random   RND = new Random();

                    SplitedString[i] = SplitedString[i].Replace("%RANDOM%" + Arg1 + "%" + Arg2 + "%", Convert.ToString(RND.Next(Convert.ToInt32(Arg1), Convert.ToInt32(Arg2))));
                }

                if (SplitedString[i].Contains("%ADD%"))
                {
                    string[] SubSplitedString = SplitedString[i].Split('%');

                    string Arg1       = SubSplitedString[2]; // Number 1
                    string Arg2       = SubSplitedString[3]; // Number 2
                    int    MathResult = Convert.ToInt32(Arg1) + Convert.ToInt32(Arg2);

                    SplitedString[i] = SplitedString[i].Replace("%ADD%" + Arg1 + "%" + Arg2 + "%", Convert.ToString(MathResult));
                }

                if (SplitedString[i].Contains("%DECREASE%"))
                {
                    string[] SubSplitedString = SplitedString[i].Split('%');
                    string   Arg1             = SubSplitedString[2]; // Number 1
                    string   Arg2             = SubSplitedString[3]; // Number 2
                    int      MathResult       = Convert.ToInt32(Arg1) - Convert.ToInt32(Arg2);

                    SplitedString[i] = SplitedString[i].Replace("%DECREASE%" + Arg1 + "%" + Arg2 + "%", Convert.ToString(MathResult));
                }

                if (SplitedString[i].Contains("%MULTIPLY%"))
                {
                    string[] SubSplitedString = SplitedString[i].Split('%');
                    string   Arg1             = SubSplitedString[2]; // Number 1
                    string   Arg2             = SubSplitedString[3]; // MultiplyTimes
                    int      MathResult       = Convert.ToInt32(Arg1) * Convert.ToInt32(Arg2);

                    SplitedString[i] = SplitedString[i].Replace("%MULTIPLY%" + Arg1 + "%" + Arg2 + "%", Convert.ToString(MathResult));
                }

                if (SplitedString[i].Contains("%DIVIDE%"))
                {
                    string[] SubSplitedString = SplitedString[i].Split('%');
                    string   Arg1             = SubSplitedString[2]; // Number 1
                    string   Arg2             = SubSplitedString[3]; // Number 2
                    int      MathResult       = Convert.ToInt32(Arg1) / Convert.ToInt32(Arg2);

                    SplitedString[i] = SplitedString[i].Replace("%DIVIDE%" + Arg1 + "%" + Arg2 + "%", Convert.ToString(MathResult));
                }

                if (SplitedString[i].Contains("%DIFERENCE%"))
                {
                    string[] SubSplitedString = SplitedString[i].Split('%');
                    string   Arg1             = SubSplitedString[2]; // Number 1
                    string   Arg2             = SubSplitedString[3]; // Number 2
                    int      MathResult       = Math.Abs(Convert.ToInt32(Arg1) - Convert.ToInt32(Arg2));


                    SplitedString[i] = SplitedString[i].Replace("%DIFERENCE%" + Arg1 + "%" + Arg2 + "%", Convert.ToString(MathResult));
                }

                if (SplitedString[i].Contains("%PERCENTAGE%"))
                {
                    string[] SubSplitedString = SplitedString[i].Split('%');
                    string   Arg1             = SubSplitedString[2]; // Number 1
                    string   Arg2             = SubSplitedString[3]; // Number 2
                    int      MathResult       = (int)Math.Round((double)(100 * Convert.ToInt32(Arg1)) / Convert.ToInt32(Arg2));


                    SplitedString[i] = SplitedString[i].Replace("%PERCENTAGE%" + Arg1 + "%" + Arg2 + "%", Convert.ToString(MathResult));
                }

                if (SplitedString[i].Contains("%LOCATION_OF%"))
                {
                    string[]  SubSplitedString = SplitedString[i].Split('%');
                    string    Arg1             = SubSplitedString[2]; // Render Type
                    string    Arg2             = SubSplitedString[3]; // Render Name
                    string    Arg3             = SubSplitedString[4]; // Value Type
                    Rectangle RectObject       = GlobalVars_Rectangle_Content[RenderQuee.Main.RenderCommand_RectangleVar.IndexOf(Arg2)];

                    int RenderNameIndex = -1;
                    if (Arg1 == "SPRITE")
                    {
                        RenderNameIndex = RenderQuee.Main.RenderCommand_Name.IndexOf(Arg2);
                    }
                    ;
                    if (Arg1 == "TEXT")
                    {
                        RenderNameIndex = RenderQuee.Main.TextRenderCommand_Name.IndexOf(Arg2);
                    }
                    ;
                    int ValToReturn = 0;
                    if (Arg3 == "X" && Arg1 == "SPRITE")
                    {
                        ValToReturn = RectObject.X;
                    }
                    ;
                    if (Arg3 == "X" && Arg1 == "TEXT")
                    {
                        ValToReturn = RenderQuee.Main.TextRenderCommand_X[RenderNameIndex];
                    }

                    if (Arg3 == "Y" && Arg1 == "SPRITE")
                    {
                        ValToReturn = RectObject.Y;
                    }
                    ;
                    if (Arg3 == "Y" && Arg1 == "TEXT")
                    {
                        ValToReturn = RenderQuee.Main.TextRenderCommand_Y[RenderNameIndex];
                    }
                    ;

                    if (Arg3 == "W" && Arg1 == "SPRITE")
                    {
                        ValToReturn = RectObject.Width;
                    }
                    ;
                    if (Arg3 == "H" && Arg1 == "SPRITE")
                    {
                        ValToReturn = RectObject.Height;
                    }
                    ;


                    SplitedString[i] = SplitedString[i].Replace("%LOCATION_OF%" + Arg1 + "%" + Arg2 + "%" + Arg3 + "%", Convert.ToString(ValToReturn));
                }

                if (SplitedString[i].Contains("%COLOR_VALUE%"))
                {
                    string[] SubSplitedString = SplitedString[i].Split('%');
                    string   Arg1             = SubSplitedString[2]; // ColorVarName
                    string   Arg2             = SubSplitedString[3]; // CodeName
                    int      ColorVarIndex    = GlobalVars_Color_Names.IndexOf(Arg1);
                    string   ValToReturn      = "0";
                    if (ColorVarIndex == -1)
                    {
                        throw new Exception("Color Variable [" + Arg1 + "] does not exist.");
                    }

                    if (Arg2.Equals("R"))
                    {
                        ValToReturn = Convert.ToString(GlobalVars_Color_Content[ColorVarIndex].R);
                    }
                    ;
                    if (Arg2.Equals("G"))
                    {
                        ValToReturn = Convert.ToString(GlobalVars_Color_Content[ColorVarIndex].G);
                    }
                    ;
                    if (Arg2.Equals("B"))
                    {
                        ValToReturn = Convert.ToString(GlobalVars_Color_Content[ColorVarIndex].B);
                    }
                    ;
                    if (Arg2.Equals("A"))
                    {
                        ValToReturn = Convert.ToString(GlobalVars_Color_Content[ColorVarIndex].A);
                    }
                    ;
                    if (Arg2.Equals("ALL"))
                    {
                        ValToReturn = GlobalVars_Color_Content[ColorVarIndex].R + "," + GlobalVars_Color_Content[ColorVarIndex].G + "," + GlobalVars_Color_Content[ColorVarIndex].B + "," + GlobalVars_Color_Content[ColorVarIndex].A;
                    }
                    ;


                    SplitedString[i] = SplitedString[i].Replace("%COLOR_VALUE%" + Arg1 + "%" + Arg2 + "%", Convert.ToString(ValToReturn));
                }


                if (SplitedString[i].Contains("%LIST_VALUE%"))
                {
                    string[] SubSplitedString = SplitedString[i].Split('%');
                    string   ValToReturn      = "null_or_incorrect";
                    string   Arg1             = SubSplitedString[2]; // ListType
                    string   Arg2             = SubSplitedString[3]; // ListName
                    string   Arg3             = SubSplitedString[4]; // Index

                    if (Arg1.Equals("STRING"))
                    {
                        int ListNameIndex = GlobalVars_StringList_Names.IndexOf(Arg2);
                        int Index         = Convert.ToInt32(Arg3);

                        ValToReturn = GlobalVars_StringList_Content[ListNameIndex][Index];
                    }

                    if (Arg1.Equals("INT"))
                    {
                        int ListNameIndex = GlobalVars_IntList_Names.IndexOf(Arg2);
                        int Index         = Convert.ToInt32(Arg3);

                        ValToReturn = Convert.ToString(GlobalVars_IntList_Content[ListNameIndex][Index]);
                    }

                    if (Arg1.Equals("COLOR"))
                    {
                        int ListNameIndex = GlobalVars_ColorList_Names.IndexOf(Arg2);
                        int Index         = Convert.ToInt32(Arg3);

                        Color  ColorGetted       = GlobalVars_ColorList_Content[ListNameIndex][Index];
                        string ColorCodeToReturn = ColorGetted.R + "," + ColorGetted.G + "," + ColorGetted.B + "," + ColorGetted.A;

                        ValToReturn = ColorCodeToReturn;
                    }

                    if (Arg1.Equals("FLOAT"))
                    {
                        int ListNameIndex = GlobalVars_FloatList_Names.IndexOf(Arg2);
                        int Index         = Convert.ToInt32(Arg3);

                        ValToReturn = Convert.ToString(GlobalVars_FloatList_Content[ListNameIndex][Index]);
                    }

                    if (Arg1.Equals("RECTANGLE"))
                    {
                        int ListNameIndex = GlobalVars_RectangleList_Names.IndexOf(Arg2);
                        int Index         = Convert.ToInt32(Arg3);

                        Rectangle RectGetted    = GlobalVars_RectangleList_Content[ListNameIndex][Index];
                        string    RectangleCode = RectGetted.X + "," + RectGetted.Y + "," + RectGetted.Width + "," + RectGetted.Height;

                        ValToReturn = Convert.ToString(RectangleCode);
                    }


                    SplitedString[i] = SplitedString[i].Replace("%LIST_VALUE%" + Arg1 + "%" + Arg2 + "%" + Arg3 + "%", Convert.ToString(ValToReturn));
                }
            }


            // Begin Command Interpretation
            if (SplitedString[0].Equals("0x0"))
            {
                Clear.Initialize();
            }
            if (SplitedString[0].Equals("0x1"))
            {
                Call.Initialize(SplitedString[1]);
            }
            if (SplitedString[0].Equals("0x2"))
            {
                Write.Initialize(SplitedString[1]);
            }
            if (SplitedString[0].Equals("0x3"))
            {
                WriteLine.Initialize(SplitedString[1]);
            }
            if (SplitedString[0].Equals("0x4"))
            {
                WriteFile.Initialize(SplitedString[1], SplitedString[2]);
            }
            if (SplitedString[0].Equals("0x5"))
            {
                TaiyouIF.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("0x6"))
            {
                Abort.Initialize();
            }
            if (SplitedString[0].Equals("0x7"))
            {
                Declare.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("0x8"))
            {
                WriteVar.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("0x9"))
            {
                MathOP.Intialize(SplitedString);
            }
            if (SplitedString[0].Equals("1x0"))
            {
                Goto.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("1x1"))
            {
                FileExists.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("1x2"))
            {
                ReadFile.Intialize(SplitedString);
            }
            if (SplitedString[0].Equals("1x3"))
            {
                DirectoryExists.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("1x4"))
            {
                DownloadServerString.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("1x5"))
            {
                CopyFile.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("1x6"))
            {
                MoveFile.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("1x7"))
            {
                DeleteFile.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("1x8"))
            {
                AddRenderQuee.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("1x9"))
            {
                AddEvent.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("2x0"))
            {
                CheckEvent.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("2x1"))
            {
                ChangeWindowPropertie.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("2x2"))
            {
                Colision.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("2x3"))
            {
                Reload.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("2x4"))
            {
                GetKeyPressed.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("2x5"))
            {
                AddRenderTextQuee.Initialize(SplitedString);
            }
            if (SplitedString[0].Equals("2x6"))
            {
                ChangeRenderProp.Initialize(SplitedString);
            }

            if (SplitedString[0].Equals("2x7"))
            {
                ChangeBackgroundColor.Initialize(SplitedString);
            }

            if (SplitedString[0].Equals("2x8"))
            {
                Undeclare.Initialize(SplitedString);
            }

            if (SplitedString[0].Equals("2x9"))
            {
                SendBGMCommand.Initialize(SplitedString);
            }

            if (SplitedString[0].Equals("3x0"))
            {
                MasterVolume.Initialize(SplitedString);
            }

            if (SplitedString[0].Equals("3x1"))
            {
                LanguageSystemManager.Initialize(SplitedString);
            }

            if (SplitedString[0].Equals("3x2"))
            {
                // FIXME Not Working
                //VarMath.Initialize(SplitedString);
            }



            if (Global.IsLowLevelDebugEnabled)
            {
                for (int i = 0; i < SplitedString.Length; i++)
                {
                    Console.Write(SplitedString[i] + " ");
                }
                Console.Write("\n");
            }
        }
 bool IPlatformService.IsDirectoryExists(string path) => DirectoryExists?.Invoke(path) ?? false;
        internal static string[] GetFiles(string projectDirectoryUnescaped, string filespecUnescaped, GetFileSystemEntries getFileSystemEntries, DirectoryExists directoryExists)
        {
            string str;
            string str2;
            string str3;
            string str4;
            bool   flag;
            bool   flag2;

            if (!HasWildcards(filespecUnescaped))
            {
                return(new string[] { filespecUnescaped });
            }
            ArrayList list        = new ArrayList();
            IList     listOfFiles = list;

            GetFileSpecInfo(filespecUnescaped, out str, out str2, out str3, out str4, out flag, out flag2, getFileSystemEntries);
            if (!flag2)
            {
                return(new string[] { filespecUnescaped });
            }
            bool stripProjectDirectory = false;

            if (projectDirectoryUnescaped != null)
            {
                if (str != null)
                {
                    string b = str;
                    try
                    {
                        str = Path.Combine(projectDirectoryUnescaped, str);
                    }
                    catch (ArgumentException)
                    {
                        return(new string[0]);
                    }
                    stripProjectDirectory = !string.Equals(str, b, StringComparison.OrdinalIgnoreCase);
                }
                else
                {
                    str = projectDirectoryUnescaped;
                    stripProjectDirectory = true;
                }
            }
            if ((str.Length > 0) && !directoryExists(str))
            {
                return(new string[0]);
            }
            bool   flag4 = (str2.Length > 0) && (str2 != ("**" + directorySeparator));
            string str6  = flag4 ? null : Path.GetExtension(str3);
            bool   flag5 = ((str6 != null) && (str6.IndexOf('*') == -1)) && (str6.EndsWith("?", StringComparison.Ordinal) || ((str6.Length == 4) && (str3.IndexOf('*') != -1)));

            GetFilesRecursive(listOfFiles, str, str2, flag4 ? null : str3, flag5 ? str6.Length : 0, flag4 ? new Regex(str4, RegexOptions.IgnoreCase) : null, flag, projectDirectoryUnescaped, stripProjectDirectory, getFileSystemEntries);
            return((string[])list.ToArray(typeof(string)));
        }
示例#17
0
        internal static string[] GetFiles(string projectDirectoryUnescaped, string filespecUnescaped, FileMatcher.GetFileSystemEntries getFileSystemEntries, DirectoryExists directoryExists)
        {
            string str;
            string str1;
            string str2;
            string str3;
            bool flag;
            bool flag1;
            string[] strArrays;
            bool flag2;
            string extension;
            bool flag3;
            string str4;
            int num;
            Regex regex;
            if (!FileMatcher.HasWildcards(filespecUnescaped))
            {
                string[] strArrays1 = new string[] { filespecUnescaped };
                return strArrays1;
            }
            ArrayList arrayLists = new ArrayList();
            IList lists = arrayLists;
            FileMatcher.GetFileSpecInfo(filespecUnescaped, out str, out str1, out str2, out str3, out flag, out flag1, getFileSystemEntries);
            if (!flag1)
            {
                string[] strArrays2 = new string[] { filespecUnescaped };
                return strArrays2;
            }
            bool flag4 = false;
            if (projectDirectoryUnescaped != null)
            {
                if (str == null)
                {
                    str = projectDirectoryUnescaped;
                    flag4 = true;
                }
                else
                {
                    string str5 = str;
                    try
                    {
                        str = Path.Combine(projectDirectoryUnescaped, str);
                    }
                    catch (ArgumentException argumentException)
                    {
                        strArrays = new string[0];
                        return strArrays;
                    }
                    flag4 = !string.Equals(str, str5, StringComparison.OrdinalIgnoreCase);
                }
            }
            if (str.Length > 0 && !directoryExists(str))
            {
                return new string[0];
            }
            flag2 = (str1.Length <= 0 ? false : str1 != string.Concat("**", FileMatcher.directorySeparator));
            bool flag5 = flag2;
            if (flag5)
            {
                extension = null;
            }
            else
            {
                extension = Path.GetExtension(str2);
            }
            string str6 = extension;
            if (str6 == null || str6.IndexOf('*') != -1)
            {
                flag3 = false;
            }
            else if (str6.EndsWith("?", StringComparison.Ordinal))
            {
                flag3 = true;
            }
            else
            {
                flag3 = (str6.Length != 4 ? false : str2.IndexOf('*') != -1);
            }
            bool flag6 = flag3;
            try
            {
                IList lists1 = lists;
                string str7 = str;
                string str8 = str1;
                if (flag5)
                {
                    str4 = null;
                }
                else
                {
                    str4 = str2;
                }
                num = (flag6 ? str6.Length : 0);
                if (flag5)
                {
                    regex = new Regex(str3, RegexOptions.IgnoreCase);
                }
                else
                {
                    regex = null;
                }
                FileMatcher.GetFilesRecursive(lists1, str7, str8, str4, num, regex, flag, projectDirectoryUnescaped, flag4, getFileSystemEntries);
                return (string[])arrayLists.ToArray(typeof(string));
            }
            catch (Exception exception)
            {

                string[] strArrays3 = new string[] { filespecUnescaped };
                strArrays = strArrays3;
            }
            return strArrays;
        }
示例#18
0
        static SearchAction GetFileSearchData(string projectDirectoryUnescaped, string filespecUnescaped,
            GetFileSystemEntries getFileSystemEntries, DirectoryExists directoryExists, out bool stripProjectDirectory,
            out RecursionState result)
        {
            stripProjectDirectory = false;
            result = new RecursionState();

            string fixedDirectoryPart;
            string wildcardDirectoryPart;
            string filenamePart;
            string matchFileExpression;
            bool needsRecursion;
            bool isLegalFileSpec;
            GetFileSpecInfo
            (
                filespecUnescaped,
                out fixedDirectoryPart,
                out wildcardDirectoryPart,
                out filenamePart,
                out matchFileExpression,
                out needsRecursion,
                out isLegalFileSpec,
                getFileSystemEntries
            );

            /*
             * If the filespec is invalid, then just return now.
             */
            if (!isLegalFileSpec)
            {
                return SearchAction.ReturnFileSpec;
            }

            // The projectDirectory is not null only if we are running the evaluation from
            // inside the engine (i.e. not from a task)
            if (projectDirectoryUnescaped != null)
            {
                if (fixedDirectoryPart != null)
                {
                    string oldFixedDirectoryPart = fixedDirectoryPart;
                    try
                    {
                        fixedDirectoryPart = Path.Combine(projectDirectoryUnescaped, fixedDirectoryPart);
                    }
                    catch (ArgumentException)
                    {
                        return SearchAction.ReturnEmptyList;
                    }

                    stripProjectDirectory = !String.Equals(fixedDirectoryPart, oldFixedDirectoryPart, StringComparison.OrdinalIgnoreCase);
                }
                else
                {
                    fixedDirectoryPart = projectDirectoryUnescaped;
                    stripProjectDirectory = true;
                }
            }

            /*
             * If the fixed directory part doesn't exist, then this means no files should be
             * returned.
             */
            if (fixedDirectoryPart.Length > 0 && !directoryExists(fixedDirectoryPart))
            {
                return SearchAction.ReturnEmptyList;
            }

            // determine if we need to use the regular expression to match the files
            // PERF NOTE: Constructing a Regex object is expensive, so we avoid it whenever possible
            bool matchWithRegex =
                // if we have a directory specification that uses wildcards, and
                (wildcardDirectoryPart.Length > 0) &&
                // the specification is not a simple "**"
                !IsRecursiveDirectoryMatch(wildcardDirectoryPart);
            // then we need to use the regular expression

            // if we're not using the regular expression, get the file pattern extension
            string extensionPart = matchWithRegex
                ? null
                : Path.GetExtension(filenamePart);

            // check if the file pattern would cause Windows to match more loosely on the extension
            // NOTE: Windows matches loosely in two cases (in the absence of the * wildcard in the extension):
            // 1) if the extension ends with the ? wildcard, it matches files with shorter extensions also e.g. "file.tx?" would
            //    match both "file.txt" and "file.tx"
            // 2) if the extension is three characters, and the filename contains the * wildcard, it matches files with longer
            //    extensions that start with the same three characters e.g. "*.htm" would match both "file.htm" and "file.html"
            bool needToEnforceExtensionLength =
                    (extensionPart != null) &&
                    (extensionPart.IndexOf('*') == -1)
                &&
                    (extensionPart.EndsWith("?", StringComparison.Ordinal)
                ||
                    ((extensionPart.Length == (3 + 1 /* +1 for the period */)) &&
                    (filenamePart.IndexOf('*') != -1)));

            var searchData = new FilesSearchData(
                // if using the regular expression, ignore the file pattern
                (matchWithRegex ? null : filenamePart), (needToEnforceExtensionLength ? extensionPart.Length : 0),
                // if using the file pattern, ignore the regular expression
                (matchWithRegex ? new Regex(matchFileExpression, RegexOptions.IgnoreCase) : null),
                needsRecursion);

            result.SearchData = searchData;
            result.BaseDirectory = fixedDirectoryPart;
            result.RemainingWildcardDirectory = wildcardDirectoryPart;

            return SearchAction.RunSearch;
        }
 internal static string[] GetFiles(string projectDirectoryUnescaped, string filespecUnescaped, GetFileSystemEntries getFileSystemEntries, DirectoryExists directoryExists)
 {
     string str;
     string str2;
     string str3;
     string str4;
     bool flag;
     bool flag2;
     if (!HasWildcards(filespecUnescaped))
     {
         return new string[] { filespecUnescaped };
     }
     ArrayList list = new ArrayList();
     IList listOfFiles = list;
     GetFileSpecInfo(filespecUnescaped, out str, out str2, out str3, out str4, out flag, out flag2, getFileSystemEntries);
     if (!flag2)
     {
         return new string[] { filespecUnescaped };
     }
     bool stripProjectDirectory = false;
     if (projectDirectoryUnescaped != null)
     {
         if (str != null)
         {
             string b = str;
             try
             {
                 str = Path.Combine(projectDirectoryUnescaped, str);
             }
             catch (ArgumentException)
             {
                 return new string[0];
             }
             stripProjectDirectory = !string.Equals(str, b, StringComparison.OrdinalIgnoreCase);
         }
         else
         {
             str = projectDirectoryUnescaped;
             stripProjectDirectory = true;
         }
     }
     if ((str.Length > 0) && !directoryExists(str))
     {
         return new string[0];
     }
     bool flag4 = (str2.Length > 0) && (str2 != ("**" + directorySeparator));
     string str6 = flag4 ? null : Path.GetExtension(str3);
     bool flag5 = ((str6 != null) && (str6.IndexOf('*') == -1)) && (str6.EndsWith("?", StringComparison.Ordinal) || ((str6.Length == 4) && (str3.IndexOf('*') != -1)));
     GetFilesRecursive(listOfFiles, str, str2, flag4 ? null : str3, flag5 ? str6.Length : 0, flag4 ? new Regex(str4, RegexOptions.IgnoreCase) : null, flag, projectDirectoryUnescaped, stripProjectDirectory, getFileSystemEntries);
     return (string[]) list.ToArray(typeof(string));
 }