Example #1
0
 private static IEnumerable <string> GetSupportedFrameworks(PackageReader packageReader)
 {
     return(packageReader
            .GetSupportedFrameworks()
            .Select(fn => fn.ToShortNameOrNull())
            .ToArray());
 }
        public void PackageReader_AgnosticFramework()
        {
            var zip = TestPackages.GetZip(TestPackages.GetLegacyContentPackage());

            using (PackageReader reader = new PackageReader(zip))
            {
                string[] frameworks = reader.GetSupportedFrameworks().Select(f => f.DotNetFrameworkName).ToArray();

                Assert.Equal("Agnostic, Version=v0.0", frameworks[0]);
                Assert.Equal(frameworks.Length, 1);
            }
        }
        public void PackageReader_SupportedFrameworks()
        {
            var zip = TestPackages.GetZip(TestPackages.GetLegacyTestPackage());

            using (PackageReader reader = new PackageReader(zip))
            {
                string[] frameworks = reader.GetSupportedFrameworks().Select(f => f.DotNetFrameworkName).ToArray();

                Assert.Equal("Any, Version=v0.0", frameworks[0]);
                Assert.Equal(".NETFramework, Version=v4.0", frameworks[1]);
                Assert.Equal(".NETFramework, Version=v4.5", frameworks[2]);
                Assert.Equal(frameworks.Length, 3);
            }
        }
Example #4
0
        public async override Task <bool> InstallPackageAsync(Packaging.Core.PackageIdentity packageIdentity, System.IO.Stream packageStream,
                                                              INuGetProjectContext nuGetProjectContext, CancellationToken token)
        {
            if (!packageStream.CanSeek)
            {
                throw new ArgumentException(NuGet.ProjectManagement.Strings.PackageStreamShouldBeSeekable);
            }

            nuGetProjectContext.Log(MessageLevel.Info, Strings.InstallingPackage, packageIdentity);

            packageStream.Seek(0, SeekOrigin.Begin);
            var           zipArchive    = new ZipArchive(packageStream);
            PackageReader packageReader = new PackageReader(zipArchive);
            var           packageSupportedFrameworks = packageReader.GetSupportedFrameworks();
            var           projectFrameworks          = _project.GetSupportedFrameworksAsync(token)
                                                       .Result
                                                       .Select(f => NuGetFramework.Parse(f.FullName));

            var args = new Dictionary <string, object>();

            args["Frameworks"] = projectFrameworks.Where(
                projectFramework =>
                IsCompatible(projectFramework, packageSupportedFrameworks)).ToArray();
            await _project.InstallPackageAsync(
                new NuGetPackageMoniker
            {
                Id      = packageIdentity.Id,
                Version = packageIdentity.Version.ToNormalizedString()
            },
                args,
                logger : null,
                progress : null,
                cancellationToken : token);

            return(true);
        }
Example #5
0
 public virtual IEnumerable <NuGetFramework> GetSupportedFrameworks(PackageReader package)
 {
     return(package.GetSupportedFrameworks());
 }
Example #6
0
        public void PackageReader_SupportedFrameworks()
        {
            var zip = TestPackages.GetZip(TestPackages.GetLegacyTestPackage());

            using (PackageReader reader = new PackageReader(zip))
            {
                string[] frameworks = reader.GetSupportedFrameworks().Select(f => f.DotNetFrameworkName).ToArray();

                Assert.Equal("Any,Version=v0.0", frameworks[0]);
                Assert.Equal(".NETFramework,Version=v4.0", frameworks[1]);
                Assert.Equal(".NETFramework,Version=v4.5", frameworks[2]);
                Assert.Equal(3, frameworks.Length);
            }
        }