示例#1
0
        public static PackageReference CreatePackageReferenceWithProjectJsonWildcardVersion(
            string package,
            string version)
        {
            string json       = "{ \"dependencies\": { \"" + package + "\": \"" + version + "\" } }";
            var    jsonObject = JObject.Parse(json);

            var dependency = JsonConfigUtility.GetDependencies(jsonObject).First();
            var identity   = new PackageIdentity(dependency.Id, dependency.VersionRange.MinVersion);

            return(new PackageReference(identity, null, true, false, false, dependency.VersionRange));
        }
        public override bool Execute()
        {
            var fullPath = ProjectJsonPath.GetMetadata("FullPath");

            using (var reader = new StreamReader(fullPath))
            {
                var json = JObject.Parse(reader.ReadToEnd());
                PackageReferences = JsonConfigUtility.GetDependencies(json)
                                    .Select(ConvertToTaskItem)
                                    .ToArray();
            }

            return(true);
        }
        public void GetDependencies_ThrowsIfObjectDoesNotHaveVersionProperty()
        {
            // Arrange
            var json = JObject.Parse(
                @"
                {
                    ""dependencies"": { 
                         ""PackageA"": { ""type"": ""build"" }
                    }
                }");

            // Act and Assert
            var ex = Assert.Throws <FormatException>(() => JsonConfigUtility.GetDependencies(json).ToList());

            // Assert
            Assert.Equal($"Dependency '{json["dependencies"].First}' has invalid version specification.", ex.Message);
        }
        public void GetDependencies_ThrowsIfVersionIsAnEmptyString()
        {
            // Arrange
            var json = JObject.Parse(
                @"
                {
                    ""dependencies"": { 
                         ""PackageA"": """"
                    }
                }");

            // Act and Assert
            var ex = Assert.Throws <FormatException>(() => JsonConfigUtility.GetDependencies(json).ToList());

            // Assert
            Assert.Equal("Dependency '\"PackageA\": \"\"' has invalid version specification.", ex.Message);
        }
示例#5
0
        public override async Task <IEnumerable <PackageReference> > GetInstalledPackagesAsync(CancellationToken token)
        {
            var packages = new List <PackageReference>();

            //  Find all dependencies and convert them into packages.config style references
            foreach (var dependency in JsonConfigUtility.GetDependencies(await GetJsonAsync()))
            {
                // Use the minimum version of the range for the identity
                var identity = new PackageIdentity(dependency.Id, dependency.VersionRange.MinVersion);

                // Pass the actual version range as the allowed range
                packages.Add(new PackageReference(identity,
                                                  targetFramework: null,
                                                  userInstalled: true,
                                                  developmentDependency: false,
                                                  requireReinstallation: false,
                                                  allowedVersions: dependency.VersionRange));
            }

            return(packages);
        }
        public void GetDependencies_ParsesIdAndVersion()
        {
            // Arrange
            var json = JObject.Parse(
                @"
                {
                    ""dependencies"": { 
                            ""PackageA"": ""1.0.0"", 
                            ""PackageC"": { ""type"": ""build"", version: ""2.0.0-beta2"" }
                    }
                }");

            // Act
            var dependencies = JsonConfigUtility.GetDependencies(json).ToList();

            // Assert
            Assert.Equal(2, dependencies.Count);
            Assert.Equal("PackageA", dependencies[0].Id);
            Assert.Equal(VersionRange.Parse("1.0.0"), dependencies[0].VersionRange);

            Assert.Equal("PackageC", dependencies[1].Id);
            Assert.Equal(VersionRange.Parse("2.0.0-beta2"), dependencies[1].VersionRange);
        }