/// <summary> /// Parses a dependency from the feed in the format: /// id or id:versionSpec, or id:versionSpec:targetFramework /// </summary> private static Tuple <string, IVersionSpec, FrameworkName> ParseDependency(string value) { if (String.IsNullOrWhiteSpace(value)) { return(null); } // IMPORTANT: Do not pass StringSplitOptions.RemoveEmptyEntries to this method, because it will break // if the version spec is null, for in that case, the Dependencies string sent down is "<id>::<target framework>". // We do want to preserve the second empty element after the split. string[] tokens = value.Trim().Split(new[] { ':' }); if (tokens.Length == 0) { return(null); } // Trim the id string id = tokens[0].Trim(); IVersionSpec versionSpec = null; if (tokens.Length > 1) { // Attempt to parse the version VersionUtility.TryParseVersionSpec(tokens[1], out versionSpec); } var targetFramework = (tokens.Length > 2 && !String.IsNullOrEmpty(tokens[2])) ? VersionUtility.ParseFrameworkName(tokens[2]) : null; return(Tuple.Create(id, versionSpec, targetFramework)); }
public IEnumerable <PackageReference> GetPackageReferences(bool requireVersion) { XDocument document = GetDocument(); if (document == null) { yield break; } foreach (var e in document.Root.Elements("package")) { string id = e.GetOptionalAttributeValue("id"); string versionString = e.GetOptionalAttributeValue("version"); string versionConstraintString = e.GetOptionalAttributeValue("allowedVersions"); string targetFrameworkString = e.GetOptionalAttributeValue("targetFramework"); SemanticVersion version = null; if (String.IsNullOrEmpty(id)) { // If the id is empty, ignore the record unless unspecified versions are allowed continue; } if (String.IsNullOrEmpty(versionString)) { // If the version is empty, ignore the record unless unspecified versions are allowed if (requireVersion) { continue; } } else if (!SemanticVersion.TryParse(versionString, out version)) { throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidVersion, versionString, _path)); } IVersionSpec versionConstaint = null; if (!String.IsNullOrEmpty(versionConstraintString)) { if (!VersionUtility.TryParseVersionSpec(versionConstraintString, out versionConstaint)) { throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidVersion, versionConstraintString, _path)); } _constraints[id] = versionConstraintString; } FrameworkName targetFramework = null; if (!String.IsNullOrEmpty(targetFrameworkString)) { targetFramework = VersionUtility.ParseFrameworkName(targetFrameworkString); if (targetFramework == VersionUtility.UnsupportedFrameworkName) { targetFramework = null; } } yield return(new PackageReference(id, version, versionConstaint, targetFramework)); } }
public PackageReferenceSet(ManifestReferenceSet manifestReferenceSet) { if (manifestReferenceSet == null) { throw new ArgumentNullException("manifestReferenceSet"); } if (!string.IsNullOrEmpty(manifestReferenceSet.TargetFramework)) { this._targetFramework = VersionUtility.ParseFrameworkName(manifestReferenceSet.TargetFramework); } this._references = new ReadOnlyHashSet <string>(from r in manifestReferenceSet.References select r.File, StringComparer.OrdinalIgnoreCase); }
private static PackageDependencySet CreatePackageDependencySet(ManifestDependencySet manifestDependencySet) { FrameworkName targetFramework = manifestDependencySet.TargetFramework == null ? null : VersionUtility.ParseFrameworkName(manifestDependencySet.TargetFramework); var dependencies = from d in manifestDependencySet.Dependencies select new PackageDependency( d.Id, String.IsNullOrEmpty(d.Version) ? null : VersionUtility.ParseVersionSpec(d.Version)); return(new PackageDependencySet(targetFramework, dependencies)); }
internal static FrameworkName ParseFrameworkFolderName(string path) { // The path for a reference might look like this for assembly foo.dll: // foo.dll // sub\foo.dll // {FrameworkName}{Version}\foo.dll // {FrameworkName}{Version}\sub1\foo.dll // {FrameworkName}{Version}\sub1\sub2\foo.dll // Get the target framework string if specified string targetFrameworkString = Path.GetDirectoryName(path).Split(Path.DirectorySeparatorChar).FirstOrDefault(); if (!String.IsNullOrEmpty(targetFrameworkString)) { return VersionUtility.ParseFrameworkName(targetFrameworkString); } return null; }
private static List <PackageReferenceSet> ReadReferenceSets(XElement referencesElement) { if (!referencesElement.HasElements) { return(new List <PackageReferenceSet>(0)); } if (referencesElement.ElementsNoNamespace("group").Any() && referencesElement.ElementsNoNamespace("reference").Any()) { throw new InvalidDataException(NuGetResources.Manifest_ReferencesHasMixedElements); } var references = ReadReference(referencesElement, throwIfEmpty: false); if (references.Any()) { // old format, <reference> is direct child of <references> var referenceSet = new PackageReferenceSet(references); return(new List <PackageReferenceSet> { referenceSet }); } else { var groups = referencesElement.ElementsNoNamespace("group"); return(groups.Select(element => { var framework = element.GetOptionalAttributeValue("targetFramework")?.Trim(); if (framework != null) { return new PackageReferenceSet(VersionUtility.ParseFrameworkName(framework), ReadReference(element, throwIfEmpty: true)); } else { return new PackageReferenceSet(ReadReference(element, throwIfEmpty: true)); } }).ToList()); } }
private static PackageDependencySet CreatePackageDependencySet(ManifestDependencySet manifestDependencySet) => new PackageDependencySet((manifestDependencySet.TargetFramework == null) ? null : VersionUtility.ParseFrameworkName(manifestDependencySet.TargetFramework), from d in manifestDependencySet.Dependencies select new PackageDependency(d.Id, string.IsNullOrEmpty(d.Version) ? null : VersionUtility.ParseVersionSpec(d.Version)));
public PackageDependencySet(string targetFramework, IEnumerable <PackageDependency> dependencies) : this(targetFramework != null ? VersionUtility.ParseFrameworkName(targetFramework) : null, dependencies) { }
private static Tuple <string, IVersionSpec, FrameworkName> ParseDependency(string value) { if (string.IsNullOrWhiteSpace(value)) { return(null); } char[] separator = new char[] { ':' }; string[] strArray = value.Trim().Split(separator); if (strArray.Length == 0) { return(null); } IVersionSpec result = null; if (strArray.Length > 1) { VersionUtility.TryParseVersionSpec(strArray[1], out result); } return(Tuple.Create <string, IVersionSpec, FrameworkName>(strArray[0].Trim(), result, ((strArray.Length <= 2) || string.IsNullOrEmpty(strArray[2])) ? null : VersionUtility.ParseFrameworkName(strArray[2]))); }
public IEnumerable <PackageReference> GetPackageReferences(bool requireVersion) { XDocument document = GetDocument(); if (document == null) { yield break; } foreach (var e in document.Root.Elements("package")) { string id = e.GetOptionalAttributeValue("id"); string versionString = e.GetOptionalAttributeValue("version"); string versionConstraintString = e.GetOptionalAttributeValue("allowedVersions"); string targetFrameworkString = e.GetOptionalAttributeValue("targetFramework"); string developmentFlagString = e.GetOptionalAttributeValue("developmentDependency"); string requireReinstallationString = e.GetOptionalAttributeValue("requireReinstallation"); SemanticVersion version = null; if (String.IsNullOrEmpty(id)) { // If the id is empty, ignore the record continue; } // If the version is invalid, raise an error unless it's both empty and not required if ((requireVersion || !String.IsNullOrEmpty(versionString)) && !SemanticVersion.TryParse(versionString, out version)) { throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidVersion, versionString, _path)); } IVersionSpec versionConstaint = null; if (!String.IsNullOrEmpty(versionConstraintString)) { if (!VersionUtility.TryParseVersionSpec(versionConstraintString, out versionConstaint)) { throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidVersion, versionConstraintString, _path)); } _constraints[id] = versionConstraintString; } FrameworkName targetFramework = null; if (!String.IsNullOrEmpty(targetFrameworkString)) { targetFramework = VersionUtility.ParseFrameworkName(targetFrameworkString); if (targetFramework == VersionUtility.UnsupportedFrameworkName) { targetFramework = null; } } var developmentFlag = false; if (!String.IsNullOrEmpty(developmentFlagString)) { if (!Boolean.TryParse(developmentFlagString, out developmentFlag)) { throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidDevelopmentFlag, developmentFlagString, _path)); } _developmentFlags[id] = developmentFlagString; } var requireReinstallation = false; if (!String.IsNullOrEmpty(requireReinstallationString)) { if (!Boolean.TryParse(requireReinstallationString, out requireReinstallation)) { throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ReferenceFile_InvalidRequireReinstallationFlag, requireReinstallationString, _path)); } } yield return(new PackageReference(id, version, versionConstaint, targetFramework, developmentFlag, requireReinstallation)); } }