public Manifest CreateManifest()
        {
            var metadata = new ManifestMetadata();

            metadata.Id      = Manifest.GetMetadata("Id");
            metadata.Version = NuGetVersion.Parse(Manifest.GetMetadata(MetadataName.Version));
            metadata.DevelopmentDependency = Manifest.GetBoolean("DevelopmentDependency");

            metadata.Title       = Manifest.GetMetadata("Title");
            metadata.Description = Manifest.GetMetadata("Description");
            metadata.Summary     = Manifest.GetMetadata("Summary");
            metadata.Language    = Manifest.GetMetadata("Language");

            metadata.Copyright = Manifest.GetMetadata("Copyright");
            metadata.RequireLicenseAcceptance = Manifest.GetBoolean("RequireLicenseAcceptance");

            if (!string.IsNullOrEmpty(Manifest.GetMetadata("Authors")))
            {
                metadata.Authors = Manifest.GetMetadata("Authors").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            }
            if (!string.IsNullOrEmpty(Manifest.GetMetadata("Owners")))
            {
                metadata.Owners = Manifest.GetMetadata("Owners").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            }

            if (!string.IsNullOrEmpty(Manifest.GetMetadata("LicenseUrl")))
            {
                metadata.SetLicenseUrl(Manifest.GetMetadata("LicenseUrl"));
            }
            if (!string.IsNullOrEmpty(Manifest.GetMetadata("ProjectUrl")))
            {
                metadata.SetProjectUrl(Manifest.GetMetadata("ProjectUrl"));
            }
            if (!string.IsNullOrEmpty(Manifest.GetMetadata("IconUrl")))
            {
                metadata.SetIconUrl(Manifest.GetMetadata("IconUrl"));
            }

            metadata.ReleaseNotes           = Manifest.GetMetadata("ReleaseNotes");
            metadata.Tags                   = Manifest.GetMetadata("Tags");
            metadata.MinClientVersionString = Manifest.GetMetadata("MinClientVersion");
            metadata.PackageTypes           = ParsePackageTypes(Manifest.GetMetadata("PackageTypes"));

            var manifest = new Manifest(metadata);

            AddDependencies(manifest);
            AddFiles(manifest);
            AddFrameworkAssemblies(manifest);

            return(manifest);
        }
Exemple #2
0
        public void ManifestValidatesMetadataUrlsIfEmpty()
        {
            // Arrange
            var manifestMetadata = new ManifestMetadata
            {
                Id          = "Foobar",
                Version     = NuGetVersion.Parse("1.0"),
                Authors     = new[] { "test-author" },
                Description = "desc"
            };

            manifestMetadata.SetIconUrl("");
            manifestMetadata.SetLicenseUrl("");
            manifestMetadata.SetProjectUrl("");

            var manifest = new Manifest(manifestMetadata);

            // Act and Assert
            ExceptionAssert.Throws <Exception>(() => Manifest.Validate(manifest),
                                               "LicenseUrl cannot be empty." + Environment.NewLine + "IconUrl cannot be empty." + Environment.NewLine + "ProjectUrl cannot be empty.");
        }
Exemple #3
0
        public Manifest CreateManifest()
        {
            var metadata = new ManifestMetadata();

            metadata.Id = Manifest.GetNullableMetadata(MetadataName.PackageId) ?? Manifest.GetMetadata("Id");

            if (Manifest.TryGetMetadata(nameof(ManifestMetadata.Version), out var version))
            {
                metadata.Version = NuGetVersion.Parse(Manifest.GetMetadata(MetadataName.Version));
            }

            if (Manifest.TryGetBoolMetadata(nameof(ManifestMetadata.DevelopmentDependency), out var devDep) && devDep)
            {
                metadata.DevelopmentDependency = true;
            }

            if (Manifest.TryGetMetadata("Title", out var title))
            {
                metadata.Title = title;
            }

            if (Manifest.TryGetMetadata("Description", out var description))
            {
                metadata.Description = description;
            }

            if (Manifest.TryGetMetadata("Summary", out var summary))
            {
                metadata.Summary = summary;
            }

            if (Manifest.TryGetMetadata("Readme", out var readme))
            {
                metadata.Readme = readme;
            }

            if (Manifest.TryGetMetadata("Language", out var language))
            {
                metadata.Language = language;
            }

            if (Manifest.TryGetMetadata("Copyright", out var copyright))
            {
                metadata.Copyright = copyright;
            }

            if (Manifest.TryGetBoolMetadata("RequireLicenseAcceptance", out var requireLicenseAcceptance) &&
                requireLicenseAcceptance)
            {
                metadata.RequireLicenseAcceptance = requireLicenseAcceptance;
            }

            if (!string.IsNullOrEmpty(Manifest.GetMetadata("Authors")))
            {
                metadata.Authors = Manifest.GetMetadata("Authors").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            }

            if (!string.IsNullOrEmpty(Manifest.GetMetadata("Owners")))
            {
                metadata.Owners = Manifest.GetMetadata("Owners").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            }

            if (!string.IsNullOrEmpty(Manifest.GetMetadata("LicenseUrl")))
            {
                metadata.SetLicenseUrl(Manifest.GetMetadata("LicenseUrl"));
            }

            if (Manifest.TryGetMetadata("LicenseExpression", out var expression))
            {
                metadata.LicenseMetadata = new LicenseMetadata(
                    LicenseType.Expression,
                    expression,
                    NuGetLicenseExpression.Parse(expression),
                    null, LicenseMetadata.CurrentVersion);
            }

            if (Manifest.TryGetMetadata("LicenseFile", out var file))
            {
                metadata.LicenseMetadata = new LicenseMetadata(
                    LicenseType.File,
                    file,
                    null,
                    null, LicenseMetadata.CurrentVersion);
            }

            if (!string.IsNullOrEmpty(Manifest.GetMetadata("ProjectUrl")))
            {
                metadata.SetProjectUrl(Manifest.GetMetadata("ProjectUrl"));
            }

            if (Manifest.TryGetMetadata("RepositoryType", out var repoType))
            {
                (metadata.Repository ??= new RepositoryMetadata()).Type = repoType;
            }

            if (Manifest.TryGetMetadata("RepositoryUrl", out var repoUrl))
            {
                (metadata.Repository ??= new RepositoryMetadata()).Url = repoUrl;
            }

            if (Manifest.TryGetMetadata("RepositoryBranch", out var repoBranch))
            {
                (metadata.Repository ??= new RepositoryMetadata()).Branch = repoBranch;
            }

            if (Manifest.TryGetMetadata("RepositoryCommit", out var repoCommit))
            {
                (metadata.Repository ??= new RepositoryMetadata()).Commit = repoCommit;
            }

            if (Manifest.TryGetMetadata("RepositorySha", out var repoSha))
            {
                (metadata.Repository ??= new RepositoryMetadata()).Commit = repoSha;
            }

            if (!string.IsNullOrEmpty(Manifest.GetMetadata("ProjectUrl")))
            {
                metadata.SetProjectUrl(Manifest.GetMetadata("ProjectUrl"));
            }

            if (!string.IsNullOrEmpty(Manifest.GetMetadata("ProjectUrl")))
            {
                metadata.SetProjectUrl(Manifest.GetMetadata("ProjectUrl"));
            }

            if (!string.IsNullOrEmpty(Manifest.GetMetadata("IconUrl")))
            {
                metadata.SetIconUrl(Manifest.GetMetadata("IconUrl"));
            }

            if (Manifest.TryGetMetadata("Icon", out var icon))
            {
                metadata.Icon = icon;
            }

            if (Manifest.TryGetMetadata("ReleaseNotes", out var releaseNotes))
            {
                metadata.ReleaseNotes = releaseNotes;
            }

            if (Manifest.TryGetMetadata("Tags", out var tags))
            {
                metadata.Tags = tags;
            }

            if (Manifest.TryGetMetadata("MinClientVersion", out var minClientVersion))
            {
                metadata.MinClientVersionString = minClientVersion;
            }

            metadata.PackageTypes = ParsePackageTypes(Manifest.GetMetadata("PackageTypes"));

            var manifest = new Manifest(metadata);

            AddDependencies(manifest);
            AddFiles(manifest);
            AddFrameworkAssemblies(manifest);

            return(manifest);
        }
Exemple #4
0
        public void ReadFromReadsAllMetadataValues()
        {
            var references = new List <PackageReferenceSet>
            {
                new PackageReferenceSet(
                    (NuGetFramework)null,
                    new [] { "Test.dll" }
                    ),
                new PackageReferenceSet(
                    NuGetFramework.Parse("hello"),
                    new [] { "world.winmd" }
                    )
            };

            // Arrange
            var manifestStream = CreateManifest(
                id: "Test-Pack2",
                version: "1.0.0-alpha",
                title: "blah",
                authors: "Outercurve",
                licenseUrl: "http://nuget.org/license", projectUrl: "http://nuget.org/project", iconUrl: "https://nuget.org/icon",
                requiresLicenseAcceptance: true, developmentDependency: true, description: "This is not a description",
                summary: "This is a summary", releaseNotes: "Release notes",
                copyright: "Copyright 2012", language: "fr-FR", tags: "Test Unit",
                dependencies: new[] { new PackageDependency("Test", VersionRange.Parse("1.2.0")) },
                assemblyReference: new[] { new FrameworkAssemblyReference("System.Data", new[] { NuGetFramework.Parse("4.0") }) },
                references: references,
                serviceable: true,
                packageTypes: new[]
            {
                new PackageType("foo", new Version(2, 0, 0)),
                new PackageType("bar", new Version(0, 0))
            },
                minClientVersion: "2.0.1.0"
                );

            var manifestMetadata = new ManifestMetadata
            {
                Id          = "Test-Pack2",
                Version     = NuGetVersion.Parse("1.0.0-alpha"),
                Description = "This is not a description",
                Authors     = new[] { "Outercurve" },
                RequireLicenseAcceptance = true,
                DevelopmentDependency    = true,
                Summary          = "This is a summary",
                ReleaseNotes     = "Release notes",
                Copyright        = "Copyright 2012",
                Language         = "fr-FR",
                Tags             = "Test Unit",
                Serviceable      = true,
                DependencyGroups = new[]
                {
                    new PackageDependencyGroup(
                        NuGetFramework.AnyFramework,
                        new []
                    {
                        new PackageDependency("Test", VersionRange.Parse("1.2.0"))
                    }
                        )
                },
                FrameworkReferences = new[]
                {
                    new FrameworkAssemblyReference("System.Data",
                                                   new [] { NuGetFramework.Parse("4.0") }
                                                   )
                },
                PackageAssemblyReferences = new[]
                {
                    new PackageReferenceSet(
                        (NuGetFramework)null,
                        new [] { "Test.dll" }
                        ),
                    new PackageReferenceSet(
                        NuGetFramework.Parse("hello"),
                        new [] { "world.winmd" }
                        )
                },
                PackageTypes = new[]
                {
                    new PackageType("foo", new Version(2, 0, 0)),
                    new PackageType("bar", new Version(0, 0))
                },
                MinClientVersionString = "2.0.1.0",
            };

            manifestMetadata.SetLicenseUrl("http://nuget.org/license");
            manifestMetadata.SetProjectUrl("http://nuget.org/project");
            manifestMetadata.SetIconUrl("https://nuget.org/icon");

            var expectedManifest = new Manifest(manifestMetadata);

            // Act
            var manifest = Manifest.ReadFrom(manifestStream, validateSchema: true);

            // Assert
            AssertManifest(expectedManifest, manifest);
        }
Exemple #5
0
        /// <summary>
        /// Gets the <see cref="ManifestMetadata" /> for a package.
        /// </summary>
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageManifest"/> class.
        /// </summary>
        /// <param name="name">The name or ID of the package.</param>
        /// <param name="version">The semantic version of the package.</param>
        /// <param name="authors">An optional semicolon delimited list of authors of the package.  The default value is &quot;UserA&quot;</param>
        /// <param name="description">An optional description of the package.  The default value is &quot;Description&quot;</param>
        /// <param name="copyright">An optional copyright of the package.</param>
        /// <param name="developmentDependency">An optional value indicating whether or not the package is a development dependency.  The default value is <code>false</code>.</param>
        /// <param name="iconUrl">An optional URL to the icon of the package.</param>
        /// <param name="language">An optional language of the package.</param>
        /// <param name="licenseUrl">An optional URL to the license of the package.</param>
        /// <param name="licenseMetadata">An optional <see cref="LicenseMetadata" /> of the package.</param>
        /// <param name="owners">An optional semicolon delimited list of owners of the package.</param>
        /// <param name="packageTypes">An optional <see cref="IEnumerable{PackageType}" /> containing the package types of the package.</param>
        /// <param name="projectUrl">An optional URL to the project of the package.</param>
        /// <param name="releaseNotes">An optional value specifying release notes of the package.</param>
        /// <param name="repositoryType">An optional value specifying the type of source code repository of the package.</param>
        /// <param name="repositoryUrl">An optional value specifying the URL of the source code repository of the package.</param>
        /// <param name="repositoryBranch">An optional value specifying the branch of the source code repository of the package.</param>
        /// <param name="repositoryCommit">An optional value specifying the commit of the source code repository of the package.</param>
        /// <param name="requireLicenseAcceptance">An optional value indicating whether or not the package requires license acceptance  The default value is <code>false</code>.</param>
        /// <param name="serviceable">An option value indicating whether or not the package is serviceable.  The default value is <code>false</code>.</param>
        /// <param name="summary">An optional summary of the package.</param>
        /// <param name="tags">An optional set of tags of the package.</param>
        /// <param name="title">An optional title of the package.</param>
        /// <returns>The <see cref="ManifestMetadata" /> for the package.</returns>
#else
        /// <summary>
        /// Gets the <see cref="ManifestMetadata" /> for a package.
        /// </summary>
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageManifest"/> class.
        /// </summary>
        /// <param name="name">The name or ID of the package.</param>
        /// <param name="version">The semantic version of the package.</param>
        /// <param name="authors">An optional semicolon delimited list of authors of the package.  The default value is &quot;UserA&quot;</param>
        /// <param name="description">An optional description of the package.  The default value is &quot;Description&quot;</param>
        /// <param name="copyright">An optional copyright of the package.</param>
        /// <param name="developmentDependency">An optional value indicating whether or not the package is a development dependency.  The default value is <code>false</code>.</param>
        /// <param name="icon">An optional path in the package that should be used for the icon of the package.</param>
        /// <param name="iconUrl">An optional URL to the icon of the package.</param>
        /// <param name="language">An optional language of the package.</param>
        /// <param name="licenseUrl">An optional URL to the license of the package.</param>
        /// <param name="licenseMetadata">An optional <see cref="LicenseMetadata" /> of the package.</param>
        /// <param name="owners">An optional semicolon delimited list of owners of the package.</param>
        /// <param name="packageTypes">An optional <see cref="IEnumerable{PackageType}" /> containing the package types of the package.</param>
        /// <param name="projectUrl">An optional URL to the project of the package.</param>
        /// <param name="releaseNotes">An optional value specifying release notes of the package.</param>
        /// <param name="repositoryType">An optional value specifying the type of source code repository of the package.</param>
        /// <param name="repositoryUrl">An optional value specifying the URL of the source code repository of the package.</param>
        /// <param name="repositoryBranch">An optional value specifying the branch of the source code repository of the package.</param>
        /// <param name="repositoryCommit">An optional value specifying the commit of the source code repository of the package.</param>
        /// <param name="requireLicenseAcceptance">An optional value indicating whether or not the package requires license acceptance  The default value is <code>false</code>.</param>
        /// <param name="serviceable">An option value indicating whether or not the package is serviceable.  The default value is <code>false</code>.</param>
        /// <param name="summary">An optional summary of the package.</param>
        /// <param name="tags">An optional set of tags of the package.</param>
        /// <param name="title">An optional title of the package.</param>
        /// <returns>The <see cref="ManifestMetadata" /> for the package.</returns>
#endif
        private static ManifestMetadata GetManifestMetadata(
            string name,
            string version,
            string authors             = null,
            string description         = null,
            string copyright           = null,
            bool developmentDependency = false,
#if !NET46
            string icon = null,
#endif
            string iconUrl    = null,
            string language   = null,
            string licenseUrl = null,
            LicenseMetadata licenseMetadata = null,
            string owners = null,
            IEnumerable <PackageType> packageTypes = null,
            string projectUrl             = null,
            string releaseNotes           = null,
            string repositoryType         = null,
            string repositoryUrl          = null,
            string repositoryBranch       = null,
            string repositoryCommit       = null,
            bool requireLicenseAcceptance = false,
            bool serviceable = false,
            string summary   = null,
            string tags      = null,
            string title     = null)
        {
            ManifestMetadata metadata = new ManifestMetadata
            {
                Authors               = MSBuildStringUtility.Split(authors ?? "UserA"),
                Copyright             = copyright,
                Description           = description ?? "Description",
                DevelopmentDependency = developmentDependency,
#if !NET46
                Icon = icon,
#endif
                Id                       = name,
                Language                 = language,
                LicenseMetadata          = licenseMetadata,
                Owners                   = string.IsNullOrWhiteSpace(owners) ? null : MSBuildStringUtility.Split(owners),
                PackageTypes             = packageTypes ?? new[] { PackageType.Dependency },
                ReleaseNotes             = releaseNotes,
                Repository               = new RepositoryMetadata(repositoryType, repositoryUrl, repositoryBranch, repositoryCommit),
                RequireLicenseAcceptance = requireLicenseAcceptance,
                Serviceable              = serviceable,
                Summary                  = summary,
                Tags                     = tags,
                Title                    = title,
                Version                  = NuGetVersion.Parse(version),
            };

            if (!string.IsNullOrWhiteSpace(iconUrl))
            {
                metadata.SetIconUrl(iconUrl);
            }

            if (!string.IsNullOrWhiteSpace(licenseUrl))
            {
                metadata.SetLicenseUrl(licenseUrl);
            }

            if (!string.IsNullOrWhiteSpace(projectUrl))
            {
                metadata.SetProjectUrl(projectUrl);
            }

            return(metadata);
        }