Exemple #1
0
        /// <summary>
        /// Clone the project's reference information and add it to the given dictionary
        /// </summary>
        /// <param name="resolver">The package reference resolver to use</param>
        /// <param name="references">The dictionary used to contain the cloned reference information</param>
        internal void CloneReferenceInfo(PackageReferenceResolver resolver, Dictionary <string,
                                                                                        Tuple <string, string, List <KeyValuePair <string, string> > > > references)
        {
            string rootPath, path;

            rootPath = Path.GetDirectoryName(this.ProjectFile.FullPath);

            // Nested project references are ignored.  We'll assume that they exist in the folder with the target
            // and they'll be found automatically.
            foreach (string refType in (new string[] { "Reference", "COMReference" }))
            {
                foreach (ProjectItem reference in this.ProjectFile.GetItems(refType))
                {
                    if (!references.ContainsKey(reference.EvaluatedInclude))
                    {
                        var metadata = reference.Metadata.Select(m => new KeyValuePair <string, string>(m.Name,
                                                                                                        m.EvaluatedValue)).ToList();
                        var hintPath = metadata.FirstOrDefault(m => m.Key == "HintPath");

                        // Convert relative paths to absolute paths
                        if (hintPath.Key != null)
                        {
                            path = reference.GetMetadataValue("HintPath");

                            if (!Path.IsPathRooted(path))
                            {
                                metadata.Remove(hintPath);
                                metadata.Add(new KeyValuePair <string, string>("HintPath",
                                                                               Path.Combine(rootPath, path)));
                            }
                        }

                        references.Add(reference.EvaluatedInclude, Tuple.Create(reference.ItemType,
                                                                                reference.EvaluatedInclude, metadata));
                    }
                }
            }

            // Resolve any package references by converting them to regular references
            if (resolver.LoadPackageReferenceInfo(this.ProjectFile))
            {
                foreach (string pr in resolver.ReferenceAssemblies)
                {
                    string refName = Path.GetFileNameWithoutExtension(pr);

                    if (!references.Keys.Any(r => r.Equals(refName, StringComparison.OrdinalIgnoreCase) ||
                                             (r.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) &&
                                              Path.GetFileNameWithoutExtension(r).Equals(refName, StringComparison.OrdinalIgnoreCase))) &&
                        File.Exists(pr))
                    {
                        references.Add(refName, Tuple.Create("Reference", refName,
                                                             new List <KeyValuePair <string, string> >
                        {
                            new KeyValuePair <string, string>("HintPath", pr),
                            new KeyValuePair <string, string>("FromPackageReference", "true")
                        }));
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Clone the project's reference information and add it to the given dictionary
 /// </summary>
 /// <param name="resolver">The package reference resolver to use</param>
 /// <param name="references">The dictionary used to contain the cloned reference information</param>
 internal void CloneReferenceInfo(PackageReferenceResolver resolver, Dictionary <string,