예제 #1
0
        // Use @search_paths to resolve the reference
        ResolvedReference ResolveReference(ITaskItem item, IEnumerable <string> search_paths, bool set_copy_local)
        {
            ResolvedReference resolved = null;
            bool specific_version;

            assembly_resolver.ResetSearchLogger();

            if (!TryGetSpecificVersionValue(item, out specific_version))
            {
                return(null);
            }

            foreach (string spath in search_paths)
            {
                assembly_resolver.LogSearchMessage("For searchpath {0}", spath);

                if (String.Compare(spath, "{HintPathFromItem}") == 0)
                {
                    resolved = assembly_resolver.ResolveHintPathReference(item, specific_version);
                }
                else if (String.Compare(spath, "{TargetFrameworkDirectory}") == 0)
                {
                    if (targetFrameworkDirectories == null)
                    {
                        continue;
                    }
                    foreach (string fpath in targetFrameworkDirectories)
                    {
                        resolved = assembly_resolver.FindInTargetFramework(item,
                                                                           fpath, specific_version);
                        if (resolved != null)
                        {
                            break;
                        }
                    }
                }
                else if (String.Compare(spath, "{GAC}") == 0)
                {
                    resolved = assembly_resolver.ResolveGacReference(item, specific_version);
                }
                else if (String.Compare(spath, "{RawFileName}") == 0)
                {
                    //FIXME: identify assembly names, as extract the name, and try with that?
                    AssemblyName aname;
                    if (assembly_resolver.TryGetAssemblyNameFromFile(item.ItemSpec, out aname))
                    {
                        resolved = assembly_resolver.GetResolvedReference(item, item.ItemSpec, aname, true,
                                                                          SearchPath.RawFileName);
                    }
                }
                else if (String.Compare(spath, "{CandidateAssemblyFiles}") == 0)
                {
                    assembly_resolver.LogSearchMessage(
                        "Warning: {{CandidateAssemblyFiles}} not supported currently");
                }
                else if (String.Compare(spath, "{PkgConfig}") == 0)
                {
                    resolved = assembly_resolver.ResolvePkgConfigReference(item, specific_version);
                }
                else
                {
                    resolved = assembly_resolver.FindInDirectory(
                        item, spath,
                        allowedAssemblyExtensions ?? default_assembly_extensions,
                        specific_version);
                }

                if (resolved != null)
                {
                    break;
                }
            }

            if (resolved != null && set_copy_local)
            {
                SetCopyLocal(resolved.TaskItem, resolved.CopyLocal.ToString());
            }

            return(resolved);
        }
예제 #2
0
        // Use @search_paths to resolve the reference
        ResolvedReference ResolveReference(ITaskItem item, IEnumerable <string> search_paths, bool set_copy_local)
        {
            ResolvedReference resolved = null;
            bool specific_version;

            assembly_resolver.ResetSearchLogger();

            if (!TryGetSpecificVersionValue(item, out specific_version))
            {
                return(null);
            }

            var spath_index = 0;

            foreach (string spath in search_paths)
            {
                assembly_resolver.LogSearchMessage("For searchpath {0}", spath);

                // The first value of search_paths can be the parent assembly directory.
                // In that case the value would be treated as a directory.
                // This code checks if we should treat the value as a TargetFramework assembly.
                // Doing so avoids CopyLocal beeing set to true.
                if (spath_index++ == 0 && targetFrameworkDirectories != null)
                {
                    foreach (string fpath in targetFrameworkDirectories)
                    {
                        if (String.Compare(
                                Path.GetFullPath(spath).TrimEnd(Path.DirectorySeparatorChar),
                                Path.GetFullPath(fpath).TrimEnd(Path.DirectorySeparatorChar),
                                StringComparison.InvariantCulture) != 0)
                        {
                            continue;
                        }

                        resolved = assembly_resolver.FindInTargetFramework(item,
                                                                           fpath, specific_version);

                        break;
                    }

                    if (resolved != null)
                    {
                        break;
                    }
                }

                if (String.Compare(spath, "{HintPathFromItem}") == 0)
                {
                    resolved = assembly_resolver.ResolveHintPathReference(item, specific_version);
                }
                else if (String.Compare(spath, "{TargetFrameworkDirectory}") == 0)
                {
                    if (targetFrameworkDirectories == null)
                    {
                        continue;
                    }
                    foreach (string fpath in targetFrameworkDirectories)
                    {
                        resolved = assembly_resolver.FindInTargetFramework(item,
                                                                           fpath, specific_version);
                        if (resolved != null)
                        {
                            break;
                        }
                    }
                }
                else if (String.Compare(spath, "{GAC}") == 0)
                {
                    resolved = assembly_resolver.ResolveGacReference(item, specific_version);
                }
                else if (String.Compare(spath, "{RawFileName}") == 0)
                {
                    //FIXME: identify assembly names, as extract the name, and try with that?
                    AssemblyName aname;
                    if (assembly_resolver.TryGetAssemblyNameFromFile(item.ItemSpec, out aname))
                    {
                        resolved = assembly_resolver.GetResolvedReference(item, item.ItemSpec, aname, true,
                                                                          SearchPath.RawFileName);
                    }
                }
                else if (String.Compare(spath, "{CandidateAssemblyFiles}") == 0)
                {
                    assembly_resolver.LogSearchMessage(
                        "Warning: {{CandidateAssemblyFiles}} not supported currently");
                }
                else if (String.Compare(spath, "{PkgConfig}") == 0)
                {
                    resolved = assembly_resolver.ResolvePkgConfigReference(item, specific_version);
                }
                else
                {
                    resolved = assembly_resolver.FindInDirectory(
                        item, spath,
                        allowedAssemblyExtensions ?? default_assembly_extensions,
                        specific_version);
                }

                if (resolved != null)
                {
                    break;
                }
            }

            if (resolved != null && set_copy_local)
            {
                SetCopyLocal(resolved.TaskItem, resolved.CopyLocal.ToString());
            }

            return(resolved);
        }