private static int GetVersionFromMetadata(ManifestMetadata metadata)
        {
            // Important: check for version 5 before version 4
            bool referencesHasTargetFramework =
                metadata.ReferenceSets != null &&
                metadata.ReferenceSets.Any(r => r.TargetFramework != null);

            if (referencesHasTargetFramework)
            {
                return(TargetFrameworkSupportForReferencesVersion);
            }

            bool dependencyHasTargetFramework =
                metadata.DependencySets != null &&
                metadata.DependencySets.Any(d => d.TargetFramework != null);

            if (dependencyHasTargetFramework)
            {
                return(TargetFrameworkSupportForDependencyContentsAndToolsVersion);
            }

            TemplatebleSemanticVersion semanticVersion;

            if (TemplatebleSemanticVersion.TryParse(metadata.Version, out semanticVersion) && !String.IsNullOrEmpty(semanticVersion.SpecialVersion))
            {
                return(SemverVersion);
            }

            return(DefaultVersion);
        }
Пример #2
0
        internal static void ValidateDependencySets(TemplatebleSemanticVersion version, IEnumerable <PackageDependencySet> dependencies)
        {
            if (version == null)
            {
                // We have independent validation for null-versions.
                return;
            }

            if (String.IsNullOrEmpty(version.SpecialVersion))
            {
                // If we are creating a production package, do not allow any of the dependencies to be a prerelease version.
                var prereleaseDependency = dependencies.SelectMany(set => set.Dependencies).FirstOrDefault(IsPrereleaseDependency);
                if (prereleaseDependency != null)
                {
                    throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_InvalidPrereleaseDependency, prereleaseDependency.ToString()));
                }
            }
        }