Example #1
0
        /// <summary>
        /// Converts a <see cref="ManifestMetadata"/> into a <see cref="NuGetManifestMetadata"/>.
        /// </summary>
        /// <param name="metadata">The metadata source of conversion.</param>
        /// <returns>A new instance of <see cref="NuGetManifestMetadata"/> corresponding to <paramref name="metadata"/>.</returns>
        public static NuGetManifestMetadata ToManifestMetadata(this ManifestMetadata metadata)
        {
            if (metadata == null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }

            var nugetMetadata = new NuGetManifestMetadata()
            {
                Id                       = metadata.Id,
                Authors                  = metadata.Authors,
                Description              = metadata.Description,
                Copyright                = metadata.Copyright,
                DevelopmentDependency    = metadata.DevelopmentDependency,
                Version                  = new NuGetVersion(metadata.Version),
                Owners                   = metadata.Owners,
                Language                 = metadata.Language,
                MinClientVersionString   = metadata.MinClientVersionString,
                ReleaseNotes             = metadata.ReleaseNotes,
                RequireLicenseAcceptance = metadata.RequireLicenseAcceptance,
                Summary                  = metadata.Summary,
                Tags                     = metadata.Tags,
                Title                    = metadata.Title
            };

            // Setting properties without a setter.
            nugetMetadata.SetIconUrl(metadata.IconUrl);
            nugetMetadata.SetLicenseUrl(metadata.LicenseUrl);
            nugetMetadata.SetProjectUrl(metadata.ProjectUrl);

            // Updating dependencies
            if (metadata.Dependencies.Count != 0)
            {
                var packages = new List <PackageDependency>();
                foreach (var dependency in metadata.Dependencies)
                {
                    packages.Add(new PackageDependency(dependency.Id, dependency.Version.ToVersionRange()));
                }
                // We are .NET agnostic
                var group = new PackageDependencyGroup(NuGetFramework.AgnosticFramework, packages);
                nugetMetadata.DependencyGroups = new [] { group };
            }

            return(nugetMetadata);
        }
Example #2
0
        private static void ReadMetadataValue(ManifestMetadata manifestMetadata, XElement element, HashSet <string> allElements)
        {
            if (element.Value == null)
            {
                return;
            }

            allElements.Add(element.Name.LocalName);

            string value = element.Value.SafeTrim();

            switch (element.Name.LocalName)
            {
            case "id":
                manifestMetadata.Id = value;
                break;

            case "version":
                manifestMetadata.Version = NuGetVersion.Parse(value);
                break;

            case "authors":
                manifestMetadata.Authors = value?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                break;

            case "owners":
                manifestMetadata.Owners = value?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                break;

            case "licenseUrl":
                manifestMetadata.SetLicenseUrl(value);
                break;

            case "projectUrl":
                manifestMetadata.SetProjectUrl(value);
                break;

            case "iconUrl":
                manifestMetadata.SetIconUrl(value);
                break;

            case "requireLicenseAcceptance":
                manifestMetadata.RequireLicenseAcceptance = XmlConvert.ToBoolean(value);
                break;

            case "developmentDependency":
                manifestMetadata.DevelopmentDependency = XmlConvert.ToBoolean(value);
                break;

            case "description":
                manifestMetadata.Description = value;
                break;

            case "summary":
                manifestMetadata.Summary = value;
                break;

            case "releaseNotes":
                manifestMetadata.ReleaseNotes = value;
                break;

            case "copyright":
                manifestMetadata.Copyright = value;
                break;

            case "language":
                manifestMetadata.Language = value;
                break;

            case "title":
                manifestMetadata.Title = value;
                break;

            case "tags":
                manifestMetadata.Tags = value;
                break;

            case "serviceable":
                manifestMetadata.Serviceable = XmlConvert.ToBoolean(value);
                break;

            case "dependencies":
                manifestMetadata.DependencyGroups = ReadDependencyGroups(element);
                break;

            case "frameworkAssemblies":
                manifestMetadata.FrameworkReferences = ReadFrameworkAssemblies(element);
                break;

            case "references":
                manifestMetadata.PackageAssemblyReferences = ReadReferenceSets(element);
                break;

            case "contentFiles":
                manifestMetadata.ContentFiles = ReadContentFiles(element);
                break;

            case "repository":
                manifestMetadata.Repository = ReadRepository(element);
                break;
            }
        }
Example #3
0
        private static void ReadMetadataValue(ManifestMetadata manifestMetadata, XElement element, HashSet <string> allElements)
        {
            if (element.Value == null)
            {
                return;
            }

            allElements.Add(element.Name.LocalName);

            string value = null;

            try
            {
                value = element.Value.SafeTrim();
                switch (element.Name.LocalName)
                {
                case "id":
                    manifestMetadata.Id = value;
                    break;

                case "version":
                    manifestMetadata.Version = NuGetVersion.Parse(value);
                    break;

                case "authors":
                    manifestMetadata.Authors = value?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    break;

                case "owners":
                    manifestMetadata.Owners = value?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    break;

                case "licenseUrl":
                    manifestMetadata.SetLicenseUrl(value);
                    break;

                case "projectUrl":
                    manifestMetadata.SetProjectUrl(value);
                    break;

                case "iconUrl":
                    manifestMetadata.SetIconUrl(value);
                    break;

                case "requireLicenseAcceptance":
                    manifestMetadata.RequireLicenseAcceptance = XmlConvert.ToBoolean(value);
                    break;

                case "developmentDependency":
                    manifestMetadata.DevelopmentDependency = XmlConvert.ToBoolean(value);
                    break;

                case "description":
                    manifestMetadata.Description = value;
                    break;

                case "summary":
                    manifestMetadata.Summary = value;
                    break;

                case "releaseNotes":
                    manifestMetadata.ReleaseNotes = value;
                    break;

                case "copyright":
                    manifestMetadata.Copyright = value;
                    break;

                case "language":
                    manifestMetadata.Language = value;
                    break;

                case "title":
                    manifestMetadata.Title = value;
                    break;

                case "tags":
                    manifestMetadata.Tags = value;
                    break;

                case "serviceable":
                    manifestMetadata.Serviceable = XmlConvert.ToBoolean(value);
                    break;

                case "dependencies":
                    manifestMetadata.DependencyGroups = ReadDependencyGroups(element);
                    break;

                case "frameworkAssemblies":
                    manifestMetadata.FrameworkReferences = ReadFrameworkAssemblies(element);
                    break;

                case "frameworkReferences":
                    manifestMetadata.FrameworkReferenceGroups = ReadFrameworkReferenceGroups(element);
                    break;

                case "references":
                    manifestMetadata.PackageAssemblyReferences = ReadReferenceSets(element);
                    break;

                case "contentFiles":
                    manifestMetadata.ContentFiles = ReadContentFiles(element);
                    break;

                case "repository":
                    manifestMetadata.Repository = ReadRepository(element);
                    break;

                case "license":
                    manifestMetadata.LicenseMetadata = ReadLicenseMetadata(element);
                    break;
                }
            }
            catch (Exception ex)
            {
                // Wrap the exception to pinpoint the exact property that is problematic,
                // and include a hint about replacement tokens.
                if (ex is InvalidDataException)
                {
                    throw ex;
                }
                else
                {
                    throw new InvalidDataException(string.Format(NuGetResources.Manifest_PropertyValueReadFailure, value, element.Name.LocalName), ex);
                }
            }
        }