Example #1
0
 public IEnumerable<string> GetCompatibleAssemblyPaths()
 {
     List<string> assemblyPaths = new List<string>();
     FrameworkReducer reducer = new FrameworkReducer();
     NuGetFramework targetFramework = new NuGetFramework(".NETFramework", Version.Parse("4.5"));  // If alternate versions of Wyam are developed (I.e., for DNX), this will need to be switched
     NuGetFrameworkFullComparer frameworkComparer = new NuGetFrameworkFullComparer();
     IPackageRepository packageRepository = PackageRepositoryFactory.Default.CreateRepository(Path);
     PackageManager packageManager = new PackageManager(packageRepository, Path);
     foreach (IPackage package in packageManager.LocalRepository.GetPackages())
     {
         List<KeyValuePair<IPackageFile, NuGetFramework>> filesAndFrameworks = package.GetLibFiles()
             .Select(x => new KeyValuePair<IPackageFile, NuGetFramework>(x,
                 new NuGetFramework(x.TargetFramework.Identifier, x.TargetFramework.Version, x.TargetFramework.Profile)))
             .ToList();
         NuGetFramework targetPackageFramework = reducer.GetNearest(targetFramework, filesAndFrameworks.Select(x => x.Value));
         if (targetPackageFramework != null)
         {
             assemblyPaths.AddRange(filesAndFrameworks
                 .Where(x => frameworkComparer.Equals(targetPackageFramework, x.Value))
                 .Select(x => System.IO.Path.Combine(Path, String.Format(CultureInfo.InvariantCulture, "{0}.{1}", package.Id, package.Version), x.Key.Path))
                 .Where(x => System.IO.Path.GetExtension(x) == ".dll"));
         }
     }
     return assemblyPaths;
 }
Example #2
0
        public void FrameworkReducer_JsonNetGetNearestLibGroup(string projectFramework, string expectedFramework)
        {
            // Arrange

            // Get nearest lib group for newtonsoft.json 7.0.1-beta2
            FrameworkReducer reducer = new FrameworkReducer();

            var project = NuGetFramework.Parse(projectFramework);

            List<NuGetFramework> frameworks = new List<NuGetFramework>()
            {
                NuGetFramework.Parse("net20"),
                NuGetFramework.Parse("net35"),
                NuGetFramework.Parse("net40"),
                NuGetFramework.Parse("net45"),
                NuGetFramework.Parse("portable-net40+wp80+win8+wpa81+sl5"),
                NuGetFramework.Parse("portable-net45+wp80+win8+wpa81+aspnetcore50")
            };

            // Act
            var result = reducer.GetNearest(project, frameworks);

            // Assert
            Assert.Equal(expectedFramework, result.GetShortFolderName());
        }
Example #3
0
        public void FrameworkReducer_GetNearestUAPTie2()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            var project = NuGetFramework.Parse("UAP10.0");

            var win = NuGetFramework.Parse("win");
            var wpa81 = NuGetFramework.Parse("wpa81");
            var native = NuGetFramework.Parse("native");
            var netcore = NuGetFramework.Parse("netcore");
            var net45 = NuGetFramework.Parse("net45");

            var all = new NuGetFramework[] { native, netcore, win, net45, wpa81 };

            var result = reducer.GetNearest(project, all);

            Assert.Equal(netcore, result);
        }
        internal static FrameworkSpecificGroup GetMostCompatibleGroup(NuGetFramework projectTargetFramework, IEnumerable<FrameworkSpecificGroup> itemGroups,
            bool altDirSeparator = false)
        {
            FrameworkReducer reducer = new FrameworkReducer();
            NuGetFramework mostCompatibleFramework = reducer.GetNearest(projectTargetFramework, itemGroups.Select(i => i.TargetFramework));
            if (mostCompatibleFramework != null)
            {
                IEnumerable<FrameworkSpecificGroup> mostCompatibleGroups = itemGroups.Where(i => i.TargetFramework.Equals(mostCompatibleFramework));
                var mostCompatibleGroup = mostCompatibleGroups.SingleOrDefault();
                if (IsValid(mostCompatibleGroup))
                {
                    mostCompatibleGroup = new FrameworkSpecificGroup(mostCompatibleGroup.TargetFramework,
                        GetValidPackageItems(mostCompatibleGroup.Items).Select(item => altDirSeparator ? PathUtility.ReplaceDirSeparatorWithAltDirSeparator(item)
                            : PathUtility.ReplaceAltDirSeparatorWithDirSeparator(item)));
                }

                return mostCompatibleGroup;
            }
            return null;
        }
Example #5
0
        // Probably going to hell for using a region
        // The following methods are originally from the internal MSBuildNuGetProjectSystemUtility class
        #region MSBuildNuGetProjectSystemUtility  

        private static FrameworkSpecificGroup GetMostCompatibleGroup(FrameworkReducer reducer, NuGetFramework projectTargetFramework,
            ICollection<FrameworkSpecificGroup> itemGroups)
        {
            NuGetFramework mostCompatibleFramework
                = reducer.GetNearest(projectTargetFramework, itemGroups.Select(i => i.TargetFramework));
            if (mostCompatibleFramework != null)
            {
                FrameworkSpecificGroup mostCompatibleGroup = itemGroups
                    .FirstOrDefault(i => i.TargetFramework.Equals(mostCompatibleFramework));

                if (IsValid(mostCompatibleGroup))
                {
                    // Normalize() is called outside GetMostCompatibleGroup() in MSBuildNuGetProjectSystemUtility but I combined it
                    return Normalize(mostCompatibleGroup);
                }
            }

            return null;
        }
Example #6
0
        public void FrameworkReducer_GetNearestAspNeg(string project, string framework)
        {
            FrameworkReducer reducer = new FrameworkReducer();

            List<NuGetFramework> frameworks = new List<NuGetFramework>()
                {
                    NuGetFramework.Parse(framework),
                };

            NuGetFramework projectFramework = NuGetFramework.Parse(project);

            var result = reducer.GetNearest(projectFramework, frameworks);

            Assert.Null(result);
        }
Example #7
0
        public void FrameworkReducer_GetNearestAzureRepro()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            List<NuGetFramework> frameworks = new List<NuGetFramework>()
                {
                    NuGetFramework.Parse("net40"),
                    NuGetFramework.Parse("portable-net45+wp8+win8+wpa"),
                    NuGetFramework.Parse("sl4")
                };

            NuGetFramework projectFramework = NuGetFramework.Parse("net45");

            var result = reducer.GetNearest(projectFramework, frameworks);

            Assert.Equal("net4", result.GetShortFolderName());
        }
Example #8
0
        public void FrameworkReducer_GetNearestWithUnsupported3()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            var all = new NuGetFramework[] { NuGetFramework.UnsupportedFramework };

            var result = reducer.GetNearest(NuGetFramework.UnsupportedFramework, all);

            Assert.Equal(NuGetFramework.UnsupportedFramework, result);
        }
Example #9
0
        public void FrameworkReducer_GetNearestChooseFrameworkName()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            var framework1 = NuGetFramework.Parse("net40");
            var framework2 = NuGetFramework.Parse("nfcore45");

            var project = NuGetFramework.Parse("net451");

            var all = new NuGetFramework[] { framework1, framework2 };

            var result = reducer.GetNearest(project, all);

            Assert.Equal(framework1, result);
        }
Example #10
0
        public void FrameworkReducer_GetNearestNonPCLtoPCLBasedOnOtherVersions()
        {
            // Arrange
            var project = NuGetFramework.Parse("win8");

            var packageFrameworks = new List<NuGetFramework>()
                {
                    NuGetFramework.Parse("portable-net45+win8+wpa81"),
                    NuGetFramework.Parse("portable-net45+win8+wpa82"),
                    NuGetFramework.Parse("portable-net45+win8+wpa9"),
                    NuGetFramework.Parse("portable-net45+win8+wpa10.0"),
                    NuGetFramework.Parse("portable-net45+win8+wpa11.0+sl5")
                };

            FrameworkReducer reducer = new FrameworkReducer();

            // Act
            var nearest = reducer.GetNearest(project, packageFrameworks);

            // Assert
            // portable-net45+win8+wpa10.0 is the best match since it has the highest
            // version of WPA, and the least frameworks
            Assert.Equal(packageFrameworks[3], nearest);
        }
Example #11
0
        public void FrameworkReducer_GetNearestDuplicatePCL()
        {
            // Verify duplicate PCLs in a folder are reduced correctly
            FrameworkReducer reducer = new FrameworkReducer();

            var project = NuGetFramework.Parse("wp8");

            var net35 = NuGetFramework.Parse("net35");
            var pcl1 = NuGetFramework.Parse("portable-net403%2Bsl5%2Bnetcore45%2Bwp8");
            var pcl2 = NuGetFramework.Parse("portable-net403%2Bsl5%2Bnetcore45%2Bwp8%2BMonoAndroid1%2BMonoTouch1");

            var all = new NuGetFramework[] { net35, pcl1, pcl2 };

            var result = reducer.GetNearest(project, all);

            Assert.Equal(pcl1, result);
        }
Example #12
0
        public void FrameworkReducer_AutoMapperGetNearestLibGroup(string projectFramework, string expectedFramework)
        {
            // Arrange

            // Get nearest lib group for AutoMapper 4.0.0-ci1026
            FrameworkReducer reducer = new FrameworkReducer();

            var project = NuGetFramework.Parse(projectFramework);

            List<NuGetFramework> frameworks = new List<NuGetFramework>()
                {
                    NuGetFramework.Parse("aspnet50"),
                    NuGetFramework.Parse("aspnetcore50"),
                    NuGetFramework.Parse("MonoAndroid"),
                    NuGetFramework.Parse("MonoTouch"),
                    NuGetFramework.Parse("net40"),
                    NuGetFramework.Parse("portable-windows8%2Bnet40%2Bwp8%2Bsl5%2BMonoAndroid%2BMonoTouch"),
                    NuGetFramework.Parse("portable-windows8%2Bnet40%2Bwp8%2Bwpa81%2Bsl5%2BMonoAndroid%2BMonoTouch"),
                    NuGetFramework.Parse("sl5"),
                    NuGetFramework.Parse("windows81"),
                    NuGetFramework.Parse("wpa81"),
                    NuGetFramework.Parse("Xamarin.iOS10")
                };

            // Act
            var result = reducer.GetNearest(project, frameworks);

            // Assert
            Assert.Equal(expectedFramework, result.GetShortFolderName());
        }
Example #13
0
        public void FrameworkReducer_GetNearestNetCore()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            var win81 = NuGetFramework.Parse("win81");
            var native = NuGetFramework.Parse("native");
            var netcore = NuGetFramework.Parse("netcore");

            var project = NuGetFramework.Parse("net451");

            var all = new NuGetFramework[] { native, netcore };

            var result = reducer.GetNearest(win81, all);

            Assert.Equal(netcore, result);
        }
Example #14
0
        public void FrameworkReducer_GetNearestUAPCore50()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            var project = NuGetFramework.Parse("UAP10.0");

            var core = NuGetFramework.Parse("core50");
            var dnx451 = NuGetFramework.Parse("dnx451");
            var dnxcore50 = NuGetFramework.Parse("dnxcore50");
            var net45 = NuGetFramework.Parse("net45");

            var all = new NuGetFramework[] { core, dnx451, dnxcore50, net45 };

            var result = reducer.GetNearest(project, all);

            Assert.Equal(core, result);
        }
        public static async Task<RegistrationInfo> GetRegistrationInfo(HttpClient httpClient, Uri registrationUri, VersionRange range, NuGetFramework projectTargetFramework, ConcurrentDictionary<Uri, JObject> sessionCache = null)
        {
            NuGetFrameworkFullComparer frameworkComparer = new NuGetFrameworkFullComparer();
            FrameworkReducer frameworkReducer = new FrameworkReducer();
            JObject index = await LoadResource(httpClient, registrationUri, sessionCache);

            if (index == null)
            {
                throw new ArgumentException(registrationUri.AbsoluteUri);
            }

            VersionRange preFilterRange = Utils.SetIncludePrerelease(range, true);

            IList<Task<JObject>> rangeTasks = new List<Task<JObject>>();

            foreach (JObject item in index["items"])
            {
                NuGetVersion lower = NuGetVersion.Parse(item["lower"].ToString());
                NuGetVersion upper = NuGetVersion.Parse(item["upper"].ToString());

                if (ResolverMetadataClientUtility.IsItemRangeRequired(preFilterRange, lower, upper))
                {
                    JToken items;
                    if (!item.TryGetValue("items", out items))
                    {
                        Uri rangeUri = item["@id"].ToObject<Uri>();

                        rangeTasks.Add(LoadResource(httpClient, rangeUri, sessionCache));
                    }
                    else
                    {
                        rangeTasks.Add(Task.FromResult(item));
                    }
                }
            }

            await Task.WhenAll(rangeTasks.ToArray());

            RegistrationInfo registrationInfo = new RegistrationInfo();

            registrationInfo.IncludePrerelease = range.IncludePrerelease;

            string id = string.Empty;

            foreach (JObject rangeObj in rangeTasks.Select((t) => t.Result))
            {
                if (rangeObj == null)
                {
                    throw new InvalidDataException(registrationUri.AbsoluteUri);
                }

                foreach (JObject packageObj in rangeObj["items"])
                {
                    JObject catalogEntry = (JObject)packageObj["catalogEntry"];

                    NuGetVersion packageVersion = NuGetVersion.Parse(catalogEntry["version"].ToString());

                    id = catalogEntry["id"].ToString();

                    int publishedDate = 0;
                    JToken publishedValue;

                    if (catalogEntry.TryGetValue("published", out publishedValue))
                    {
                        publishedDate = int.Parse(publishedValue.ToObject<DateTime>().ToString("yyyyMMdd"));
                    }

                    //publishedDate = 0 means the property doesn't exist in index.json
                    //publishedDate = 19000101 means the property exists but the package is unlisted
                    if (range.Satisfies(packageVersion) && (publishedDate!= 19000101))
                    {
                        PackageInfo packageInfo = new PackageInfo();
                        packageInfo.Version = packageVersion;
                        packageInfo.PackageContent = new Uri(packageObj["packageContent"].ToString());

                        JArray dependencyGroupsArray = (JArray)catalogEntry["dependencyGroups"];

                        if (dependencyGroupsArray != null)
                        {
                            // only one target framework group will be used at install time, which means 
                            // we can filter down to that group now by using the project target framework
                            var depFrameworks = dependencyGroupsArray.Select(e => GetFramework(e as JObject));

                            var targetFramework = frameworkReducer.GetNearest(projectTargetFramework, depFrameworks);

                            // If no frameworks are compatible we just ignore them - Should this be an exception?
                            if (targetFramework != null)
                            {
                                foreach (JObject dependencyGroupObj in dependencyGroupsArray)
                                {
                                    NuGetFramework currentFramework = GetFramework(dependencyGroupObj);

                                    if (frameworkComparer.Equals(currentFramework, targetFramework))
                                    {
                                        foreach (JObject dependencyObj in dependencyGroupObj["dependencies"])
                                        {
                                            DependencyInfo dependencyInfo = new DependencyInfo();
                                            dependencyInfo.Id = dependencyObj["id"].ToString();
                                            dependencyInfo.Range = Utils.CreateVersionRange((string)dependencyObj["range"], range.IncludePrerelease);
                                            dependencyInfo.RegistrationUri = dependencyObj["registration"].ToObject<Uri>();

                                            packageInfo.Dependencies.Add(dependencyInfo);
                                        }
                                    }
                                }
                            }
                        }

                        registrationInfo.Add(packageInfo);
                    }
                }

                registrationInfo.Id = id;
            }

            return registrationInfo;
        }
Example #16
0
        public void FrameworkReducer_GetNearestPCLtoPCLVersions()
        {
            var project = NuGetFramework.Parse("portable-net45+win81");

            var packageFrameworks = new List<NuGetFramework>()
                {
                    NuGetFramework.Parse("portable-net40+win81+sl5"),
                    NuGetFramework.Parse("portable-net45+win8+sl5"),
                    NuGetFramework.Parse("portable-net45+win81+wpa81+monotouch+monoandroid"),
                };

            FrameworkReducer reducer = new FrameworkReducer();

            var nearest = reducer.GetNearest(project, packageFrameworks);

            // portable-net45+win81+wpa81+monotouch+monoandroid is nearest to the original
            Assert.Equal(packageFrameworks[2], nearest);
        }
Example #17
0
        public void FrameworkReducer_GetNearestNonPCLtoPCL()
        {
            var project = NuGetFramework.Parse("win9");

            var packageFrameworks = new List<NuGetFramework>()
                {
                    NuGetFramework.Parse("portable-net45+win8"),
                    NuGetFramework.Parse("portable-net45+win82"),
                    NuGetFramework.Parse("portable-net45+win81"),
                    NuGetFramework.Parse("portable-net45+win91"),
                };

            FrameworkReducer reducer = new FrameworkReducer();

            var nearest = reducer.GetNearest(project, packageFrameworks);

            // win82 is the best match for win9
            Assert.Equal(packageFrameworks[1], nearest);
        }
Example #18
0
        public void FrameworkReducer_GetNearestProfile()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            var project = NuGetFramework.Parse("net45-client");

            var net40 = NuGetFramework.Parse("net40");
            var net40client = NuGetFramework.Parse("net40-client");

            var all = new NuGetFramework[] { net40, net40client };

            var result = reducer.GetNearest(project, all);

            Assert.Equal(net40client, result);
        }
Example #19
0
        public void FrameworkReducer_GetNearestNonPCLtoPCLUncertain()
        {
            // Arrange
            var project = NuGetFramework.Parse("win8");

            var packageFrameworks = new List<NuGetFramework>()
                {
                    NuGetFramework.Parse("portable-net45+win8+sl6"),
                    NuGetFramework.Parse("portable-net45+win8+dnxcore50"),
                    NuGetFramework.Parse("portable-net45+win8+native"),
                };

            FrameworkReducer reducer = new FrameworkReducer();

            // Act
            var nearest = reducer.GetNearest(project, packageFrameworks);

            // Assert
            // There is no certain way to relate these frameworks to each other, but the same one
            // should always come back from this compare.
            Assert.Equal(packageFrameworks[1], nearest);
        }
Example #20
0
        public void FrameworkReducer_GetNearestWinRT()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            var win81 = NuGetFramework.Parse("win81");
            var native = NuGetFramework.Parse("native");
            var winrt45 = NuGetFramework.Parse("winrt45");

            var project = NuGetFramework.Parse("net451");

            var all = new NuGetFramework[] { native, winrt45 };

            var result = reducer.GetNearest(win81, all);

            Assert.Equal(winrt45, result);
        }
Example #21
0
        public void FrameworkReducer_GetNearestEquivalent()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            var framework1 = NuGetFramework.Parse("net40");
            var framework2 = NuGetFramework.Parse("net40-client");

            var project = NuGetFramework.Parse("net45");

            var all = new NuGetFramework[] { framework1, framework2 };

            var result = reducer.GetNearest(project, all);

            Assert.Equal(framework1, result);
        }
Example #22
0
        public void FrameworkReducer_GetNearestWin()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            var win81 = NuGetFramework.Parse("win81");
            var win8 = NuGetFramework.Parse("win8");
            var netcore = NuGetFramework.Parse("netcore");
            var nfcore = NuGetFramework.Parse("nfcore");
            var native = NuGetFramework.Parse("native");
            var netcore451 = NuGetFramework.Parse("netcore451");
            var winrt45 = NuGetFramework.Parse("winrt45");

            var project = NuGetFramework.Parse("net451");

            var all = new NuGetFramework[] { win8, netcore, nfcore, native, netcore451, winrt45 };

            var result = reducer.GetNearest(win81, all);

            Assert.Equal(netcore451, result);
        }
Example #23
0
        public void FrameworkReducer_GetNearest2()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            var net35 = NuGetFramework.Parse("net35");
            var net40 = NuGetFramework.Parse("net40");
            var net45 = NuGetFramework.Parse("net45");
            var net451 = NuGetFramework.Parse("net451");
            var net453 = NuGetFramework.Parse("net453");

            var all = new NuGetFramework[] { net35, net40, net45, net451, net453 };

            var result = reducer.GetNearest(net451, all);

            Assert.Equal(net451, result);
        }
Example #24
0
        public void FrameworkReducer_GetNearestAny()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            var dnxcore50 = NuGetFramework.Parse("dnxcore50");
            var core50 = NuGetFramework.Parse("core50");

            var all = new NuGetFramework[] { dnxcore50, core50 };

            var result = reducer.GetNearest(NuGetFramework.AnyFramework, all);

            Assert.Equal(dnxcore50, result);
        }
Example #25
0
        public void FrameworkReducer_GetNearestWithAnyOnly()
        {
            FrameworkReducer reducer = new FrameworkReducer();

            var net45 = NuGetFramework.Parse("net45");

            var all = new NuGetFramework[] { NuGetFramework.AnyFramework };

            var result = reducer.GetNearest(net45, all);

            Assert.Equal(NuGetFramework.AnyFramework, result);
        }
Example #26
0
        public void FrameworkReducer_GetNearestPCLtoPCL2()
        {
            var project = NuGetFramework.Parse("portable-net45+sl5+monotouch+monoandroid");

            var packageFrameworks = new List<NuGetFramework>()
                {
                    NuGetFramework.Parse("portable-net45+sl5"),
                    NuGetFramework.Parse("portable-net40+sl5+monotouch"),
                    NuGetFramework.Parse("portable-net40+sl4+monotouch+monoandroid"),
                    NuGetFramework.Parse("portable-net40+sl4+monotouch+monoandroid+wp71"),
                };

            FrameworkReducer reducer = new FrameworkReducer();

            var nearest = reducer.GetNearest(project, packageFrameworks);

            Assert.Equal(packageFrameworks[0], nearest);
        }
Example #27
0
        public void FrameworkReducer_GetNearestDnx(string project, string framework)
        {
            FrameworkReducer reducer = new FrameworkReducer();

            List<NuGetFramework> frameworks = new List<NuGetFramework>()
                {
                    NuGetFramework.Parse(framework),
                };

            NuGetFramework projectFramework = NuGetFramework.Parse(project);

            var result = reducer.GetNearest(projectFramework, frameworks);

            Assert.True(NuGetFramework.Parse(framework).Equals(result));
        }
Example #28
0
        public void FrameworkReducer_GetNearestPCLtoPCL()
        {
            // Arrange
            var project = NuGetFramework.Parse("portable-net45+win81");

            var packageFrameworks = new List<NuGetFramework>()
                {
                    NuGetFramework.Parse("portable-net45+win8"),
                    NuGetFramework.Parse("portable-net40+win8"),
                    NuGetFramework.Parse("portable-net40+win81"),
                };

            FrameworkReducer reducer = new FrameworkReducer();

            // Act
            var nearest = reducer.GetNearest(project, packageFrameworks);

            // Assert
            // net45+win8 is nearest since net45 wins over net40
            Assert.Equal(packageFrameworks[0], nearest);
        }
        /// <summary>
        /// Adds refresh files to the specified project for all assemblies references belonging to the packages specified by packageNames.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <param name="packagesFileSystem">The file system pointing to 'packages' folder under the solution.</param>
        /// <param name="packageNames">The package names.</param>
        private void AddRefreshFilesForReferences(Project project, string repositoryPath, IEnumerable<PackageIdentity> packageNames)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            if (repositoryPath == null)
            {
                throw new ArgumentNullException("repositoryPath");
            }

            if (!packageNames.Any())
            {
                return;
            }

            VSAPIProjectContext context = new VSAPIProjectContext();
            WebSiteProjectSystem projectSystem = new WebSiteProjectSystem(project, context);

            var root = EnvDTEProjectUtility.GetFullPath(project);

            foreach (var packageName in packageNames)
            {
                string packagePath = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", packageName.Id, packageName.Version);

                DirectoryInfo packageFolder = new DirectoryInfo(Path.Combine(repositoryPath, packagePath));

                PackageFolderReader reader = new PackageFolderReader(packageFolder);

                var frameworkGroups = reader.GetReferenceItems();

                var groups = reader.GetReferenceItems();

                var fwComparer = new NuGetFrameworkFullComparer();
                FrameworkReducer reducer = new FrameworkReducer();
                NuGetFramework targetGroupFramework = reducer.GetNearest(projectSystem.TargetFramework, groups.Select(e => e.TargetFramework));

                if (targetGroupFramework != null)
                {
                    var refGroup = groups.Where(e => fwComparer.Equals(targetGroupFramework, e.TargetFramework)).FirstOrDefault();

                    foreach (string refItem in refGroup.Items)
                    {
                        string sourcePath = Path.Combine(packageFolder.FullName, refItem.Replace('/', Path.DirectorySeparatorChar));

                        // create one refresh file for each assembly reference, as per required by Website projects
                        // projectSystem.CreateRefreshFile(assemblyPath);
                        RefreshFileUtility.CreateRefreshFile(projectSystem, sourcePath, context);
                    }
                }
            }
        }
Example #30
0
        /// <summary>
        /// Retrieve a registration blob
        /// </summary>
        /// <returns>Returns Null if the package does not exist</returns>
        public static async Task<RegistrationInfo> GetRegistrationInfo(
            HttpClient httpClient,
            Uri registrationUri,
            VersionRange range,
            NuGetFramework projectTargetFramework,
            CancellationToken token)
        {
            var frameworkComparer = new NuGetFrameworkFullComparer();
            var frameworkReducer = new FrameworkReducer();
            var dependencies = await GetDependencies(httpClient, registrationUri, range, token);
            
            var registrationInfo = new RegistrationInfo();

            registrationInfo.IncludePrerelease = range.IncludePrerelease;
            foreach (var item in dependencies)
            {
                var packageInfo = new PackageInfo
                    {
                        Listed = item.Listed,
                        Version = item.Identity.Version,
                        PackageContent = new Uri(item.ContentUri)
                    };

                // only one target framework group will be used at install time, which means 
                // we can filter down to that group now by using the project target framework
                var depFrameworks = item.DependencyGroups.Select(e => e.TargetFramework);
                var targetFramework = frameworkReducer.GetNearest(projectTargetFramework, depFrameworks);

                // If no frameworks are compatible we just ignore them - Should this be an exception?
                if (targetFramework != null)
                {
                    var dependencyGroup = item.DependencyGroups.FirstOrDefault(d => frameworkComparer.Equals(targetFramework, d.TargetFramework));
                    if (dependencyGroup != null)
                    {
                        foreach (var dependency in dependencyGroup.Packages)
                        {
                            var dependencyInfo = new DependencyInfo
                                {
                                    Id = dependency.Id,
                                    Range = dependency.VersionRange
                                };

                            packageInfo.Dependencies.Add(dependencyInfo);
                        }
                    }
                }

                registrationInfo.Add(packageInfo);
                registrationInfo.Id = item.Identity.Id;
            }

            return registrationInfo;
        }