public override bool Resolve(AssemblyNameExtension assemblyName, string rawFileNameCandidate, bool isPrimaryProjectReference, bool wantSpecificVersion, string[] executableExtensions, string hintPath, string assemblyFolderKey, ArrayList assembliesConsideredAndRejected, out string foundPath, out bool userRequestedSpecificFile)
 {
     foundPath = null;
     userRequestedSpecificFile = false;
     if (assemblyName != null)
     {
         string path = GlobalAssemblyCache.GetLocation(assemblyName, base.targetProcessorArchitecture, base.getRuntimeVersion, base.targetedRuntimeVersion, false, base.fileExists, null, null, wantSpecificVersion);
         if (((path != null) && (path.Length > 0)) && base.fileExists(path))
         {
             foundPath = path;
             return(true);
         }
         if (assembliesConsideredAndRejected != null)
         {
             ResolutionSearchLocation location = new ResolutionSearchLocation {
                 FileNameAttempted = assemblyName.FullName,
                 SearchPath        = base.searchPathElement,
                 AssemblyName      = assemblyName,
                 Reason            = NoMatchReason.NotInGac
             };
             assembliesConsideredAndRejected.Add(location);
         }
     }
     return(false);
 }
示例#2
0
        /// <summary>
        /// Resolve a reference to a specific file name.
        /// </summary>
        /// <param name="assemblyName">The assemblyname of the reference.</param>
        /// <param name="rawFileNameCandidate">The reference's 'include' treated as a raw file name.</param>
        /// <param name="isPrimaryProjectReference">Whether or not this reference was directly from the project file (and therefore not a dependency)</param>
        /// <param name="wantSpecificVersion">Whether an exact version match is requested.</param>
        /// <param name="executableExtensions">Allowed executable extensions.</param>
        /// <param name="hintPath">The item's hintpath value.</param>
        /// <param name="assemblyFolderKey">Like "hklm\Vendor RegKey" as provided to a reference by the <AssemblyFolderKey> on the reference in the project.</param>
        /// <param name="candidateAssemblyFiles">List of literal assembly file names to be considered when SearchPaths has {CandidateAssemblyFiles}.</param>
        /// <param name="assembliesConsideredAndRejected">Receives the list of locations that this function tried to find the assembly. May be "null".</param>
        /// <param name="foundPath">The path where the file was found.</param>
        /// <param name="userRequestedSpecificFile">Whether or not the user wanted a specific file (for example, HintPath is a request for a specific file)</param>
        /// <returns>True if the file was resolved.</returns>
        public override bool Resolve
        (
            AssemblyNameExtension assemblyName,
            string sdkName,
            string rawFileNameCandidate,
            bool isPrimaryProjectReference,
            bool wantSpecificVersion,
            string[] executableExtensions,
            string hintPath,
            string assemblyFolderKey,
            ArrayList assembliesConsideredAndRejected,
            out string foundPath,
            out bool userRequestedSpecificFile
        )
        {
            foundPath = null;
            userRequestedSpecificFile = false;

            if (assemblyName != null)
            {
                // {GAC} was passed in.
                string gacResolved = GlobalAssemblyCache.GetLocation(_buildEngine, assemblyName, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, false /*may not be a fusion name*/, fileExists, null /*Use default delegate in method*/, null /*Use default delegate in method*/, wantSpecificVersion);
                if (gacResolved != null && gacResolved.Length > 0 && fileExists(gacResolved))
                {
                    foundPath = gacResolved;
                    return(true);
                }
                else
                {
                    // Record this as a location that was considered.
                    if (assembliesConsideredAndRejected != null)
                    {
                        ResolutionSearchLocation considered = new ResolutionSearchLocation();
                        considered.FileNameAttempted = assemblyName.FullName;
                        considered.SearchPath        = searchPathElement;
                        considered.AssemblyName      = assemblyName;
                        considered.Reason            = NoMatchReason.NotInGac;
                        assembliesConsideredAndRejected.Add(considered);
                    }
                }
            }


            return(false);
        }
        /// <summary>
        /// If the target framework moniker is set, generate the correct Paths.
        /// </summary>
        public override bool Execute()
        {
            FrameworkNameVersioning moniker = null;
            FrameworkNameVersioning monikerWithNoProfile = null;

            // Are we targeting a profile.
            bool targetingProfile = false;

            try
            {
                moniker          = new FrameworkNameVersioning(TargetFrameworkMoniker);
                targetingProfile = !String.IsNullOrEmpty(moniker.Profile);

                // If we are targeting a profile we need to generate a set of reference assembly paths which describe where the full framework
                //  exists, to do so we need to get the reference assembly location without the profile as part of the moniker.
                if (targetingProfile)
                {
                    monikerWithNoProfile = new FrameworkNameVersioning(moniker.Identifier, moniker.Version);
                }

#if FEATURE_GAC
                // This is a very specific "hack" to ensure that when we're targeting certain .NET Framework versions that
                // WPF gets to rely on .NET FX 3.5 SP1 being installed on the build machine.
                // This only needs to occur when we are targeting a .NET FX prior to v4.0
                if (!_bypassFrameworkInstallChecks && moniker.Identifier.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase) &&
                    moniker.Version.Major < 4)
                {
                    // We have not got a value for whether or not the 35 sentinel assembly has been found
                    if (!s_net35SP1SentinelAssemblyFound.HasValue)
                    {
                        // get an assemblyname from the string representation of the sentinel assembly name
                        AssemblyNameExtension sentinelAssemblyName = new AssemblyNameExtension(s_NET35SP1SentinelAssemblyName);

                        string path = GlobalAssemblyCache.GetLocation(sentinelAssemblyName, SystemProcessorArchitecture.MSIL, runtimeVersion => "v2.0.50727", new Version("2.0.57027"), false, new FileExists(FileUtilities.FileExistsNoThrow), GlobalAssemblyCache.pathFromFusionName, GlobalAssemblyCache.gacEnumerator, false);
                        s_net35SP1SentinelAssemblyFound = !String.IsNullOrEmpty(path);
                    }

                    // We did not find the SP1 sentinel assembly in the GAC. Therefore we must assume that SP1 isn't installed
                    if (!s_net35SP1SentinelAssemblyFound.Value)
                    {
                        Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.NETFX35SP1NotIntstalled", TargetFrameworkMoniker);
                    }
                }
#endif
            }
            catch (ArgumentException e)
            {
                Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.InvalidTargetFrameworkMoniker", TargetFrameworkMoniker, e.Message);
                return(false);
            }

            try
            {
                _tfmPaths = GetPaths(_rootPath, moniker);

                if (_tfmPaths != null && _tfmPaths.Count > 0)
                {
                    TargetFrameworkMonikerDisplayName = ToolLocationHelper.GetDisplayNameForTargetFrameworkDirectory(_tfmPaths[0], moniker);
                }

                // If there is a profile get the paths without the profile.
                // There is no point in generating the full framework paths if profile path could not be found.
                if (targetingProfile && _tfmPaths != null)
                {
                    _tfmPathsNoProfile = GetPaths(_rootPath, monikerWithNoProfile);
                }

                // The path with out the profile is just the reference assembly paths.
                if (!targetingProfile)
                {
                    _tfmPathsNoProfile = _tfmPaths;
                }
            }
            catch (Exception e)
            {
                // The reason we need to do exception E here is because we are in a task and have the ability to log the message and give the user
                // feedback as to its cause, tasks if at all possible should not have exception leave them.
                Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.ProblemGeneratingReferencePaths", TargetFrameworkMoniker, e.Message);

                if (ExceptionHandling.IsCriticalException(e))
                {
                    throw;
                }

                _tfmPathsNoProfile = null;
                TargetFrameworkMonikerDisplayName = null;
            }

            return(!Log.HasLoggedErrors);
        }
示例#4
0
        public override bool Execute()
        {
            FrameworkName frameworkmoniker = null;
            FrameworkName name2            = null;
            bool          flag             = false;

            try
            {
                frameworkmoniker = new FrameworkName(this.TargetFrameworkMoniker);
                flag             = !string.IsNullOrEmpty(frameworkmoniker.Profile);
                if (flag)
                {
                    name2 = new FrameworkName(frameworkmoniker.Identifier, frameworkmoniker.Version);
                }
                if ((!this.bypassFrameworkInstallChecks && frameworkmoniker.Identifier.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase)) && (frameworkmoniker.Version.Major < 4))
                {
                    if (!net35SP1SentinelAssemblyFound.HasValue)
                    {
                        AssemblyNameExtension strongName = new AssemblyNameExtension(NET35SP1SentinelAssemblyName);
                        net35SP1SentinelAssemblyFound = new bool?(!string.IsNullOrEmpty(GlobalAssemblyCache.GetLocation(strongName, System.Reflection.ProcessorArchitecture.MSIL, runtimeVersion => "v2.0.50727", new Version("2.0.57027"), false, new Microsoft.Build.Shared.FileExists(Microsoft.Build.Shared.FileUtilities.FileExistsNoThrow), GlobalAssemblyCache.pathFromFusionName, GlobalAssemblyCache.gacEnumerator, false)));
                    }
                    if (!net35SP1SentinelAssemblyFound.Value)
                    {
                        base.Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.NETFX35SP1NotIntstalled", new object[] { this.TargetFrameworkMoniker });
                    }
                }
            }
            catch (ArgumentException exception)
            {
                base.Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.InvalidTargetFrameworkMoniker", new object[] { this.TargetFrameworkMoniker, exception.Message });
                return(false);
            }
            try
            {
                this.tfmPaths = this.GetPaths(this.rootPath, frameworkmoniker);
                if ((this.tfmPaths != null) && (this.tfmPaths.Count > 0))
                {
                    this.TargetFrameworkMonikerDisplayName = ToolLocationHelper.GetDisplayNameForTargetFrameworkDirectory(this.tfmPaths[0], frameworkmoniker);
                }
                if (flag && (this.tfmPaths != null))
                {
                    this.tfmPathsNoProfile = this.GetPaths(this.rootPath, name2);
                }
                if (!flag)
                {
                    this.tfmPathsNoProfile = this.tfmPaths;
                }
            }
            catch (Exception exception2)
            {
                base.Log.LogErrorWithCodeFromResources("GetReferenceAssemblyPaths.ProblemGeneratingReferencePaths", new object[] { this.TargetFrameworkMoniker, exception2.Message });
                if (Microsoft.Build.Shared.ExceptionHandling.IsCriticalException(exception2))
                {
                    throw;
                }
                this.tfmPathsNoProfile = null;
                this.TargetFrameworkMonikerDisplayName = null;
            }
            return(!base.Log.HasLoggedErrors);
        }