static IEnumerable <string> FindAssemblyReferences( NuGetFramework projectFramework, DependencyInfoResource dependencyResource, FindLocalPackagesResource localPackageResource, SourceCacheContext cacheContext, string packageId) { var packageInfo = localPackageResource.FindPackagesById(packageId, NullLogger.Instance, CancellationToken.None).FirstOrDefault(); if (packageInfo == null) { yield break; } using (var reader = packageInfo.GetReader()) { var nearestFramework = reader.GetReferenceItems().GetNearest(projectFramework); if (nearestFramework != null) { foreach (var assembly in nearestFramework.Items) { yield return(Path.GetFileName(assembly)); } } } var dependencyInfo = dependencyResource.ResolvePackage(packageInfo.Identity, projectFramework, cacheContext, NullLogger.Instance, CancellationToken.None).Result; foreach (var dependency in dependencyInfo.Dependencies) { foreach (var reference in FindAssemblyReferences(projectFramework, dependencyResource, localPackageResource, cacheContext, dependency.Id)) { yield return(reference); } } }
static IEnumerable<string> FindAssemblyReferences( NuGetFramework projectFramework, DependencyInfoResource dependencyResource, FindLocalPackagesResource localPackageResource, SourceCacheContext cacheContext, string packageId) { var packageInfo = localPackageResource.FindPackagesById(packageId, NullLogger.Instance, CancellationToken.None).FirstOrDefault(); if (packageInfo == null) yield break; using (var reader = packageInfo.GetReader()) { var assemblyReferences = reader.GetReferenceItems().GetNearest(projectFramework); if (assemblyReferences != null) { foreach (var assembly in assemblyReferences.Items) { yield return Path.GetFileName(assembly); } } var buildReferences = reader.GetBuildItems().GetNearest(projectFramework); if (buildReferences != null) { var buildProperties = buildReferences.Items.FirstOrDefault(item => Path.GetExtension(item) == PropertyExtension); if (buildProperties != null) { using (var propertyStream = reader.GetStream(buildProperties)) using (var propertyReader = XmlReader.Create(propertyStream)) { while (propertyReader.ReadToFollowing(ReferenceElement)) { var assemblyName = propertyReader.GetAttribute(IncludeAttribute); yield return Path.ChangeExtension(assemblyName, DllExtension); } } } } } var dependencyInfo = dependencyResource.ResolvePackage(packageInfo.Identity, projectFramework, cacheContext, NullLogger.Instance, CancellationToken.None).Result; foreach (var dependency in dependencyInfo.Dependencies) { foreach (var reference in FindAssemblyReferences(projectFramework, dependencyResource, localPackageResource, cacheContext, dependency.Id)) { yield return reference; } } }