/// <summary> /// Creates a NuGetFramework from a folder name using the given mappings. /// </summary> public static NuGetFramework ParseFolder(string folderName, IFrameworkNameProvider mappings) { if (folderName == null) { throw new ArgumentNullException(nameof(folderName)); } if (mappings == null) { throw new ArgumentNullException(nameof(mappings)); } if (folderName.IndexOf('%') > -1) { folderName = Uri.UnescapeDataString(folderName); } NuGetFramework result = null; // first check if we have a special or common framework if (!TryParseSpecialFramework(folderName, out result) && !TryParseCommonFramework(folderName, out result)) { // assume this is unsupported unless we find a match result = UnsupportedFramework; var parts = RawParse(folderName); if (parts != null) { string framework = null; if (mappings.TryGetIdentifier(parts.Item1, out framework)) { var version = FrameworkConstants.EmptyVersion; if (parts.Item2 == null || mappings.TryGetVersion(parts.Item2, out version)) { var profileShort = parts.Item3; string profile = null; if (!mappings.TryGetProfile(framework, profileShort, out profile)) { profile = profileShort ?? string.Empty; } if (StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.Portable, framework)) { IEnumerable<NuGetFramework> clientFrameworks = null; mappings.TryGetPortableFrameworks(profileShort, out clientFrameworks); var profileNumber = -1; if (mappings.TryGetPortableProfile(clientFrameworks, out profileNumber)) { var portableProfileNumber = FrameworkNameHelpers.GetPortableProfileNumberString(profileNumber); result = new NuGetFramework(framework, version, portableProfileNumber); } else { // TODO: should this be unsupported? result = new NuGetFramework(framework, version, profileShort); } } else { result = new NuGetFramework(framework, version, profile); } } } } else { // If the framework was not recognized check if it is a deprecated framework NuGetFramework deprecated = null; if (TryParseDeprecatedFramework(folderName, out deprecated)) { result = deprecated; } } } return result; }
/// <summary> /// Creates a NuGetFramework from a folder name using the given mappings. /// </summary> public static NuGetFramework ParseFolder(string folderName, IFrameworkNameProvider mappings) { if (folderName == null) { throw new ArgumentNullException("folderName"); } if (mappings == null) { throw new ArgumentNullException("mappings"); } if (folderName.IndexOf('%') > -1) { folderName = Uri.UnescapeDataString(folderName); } NuGetFramework result = null; // first check if we have a special or common framework if (!TryParseSpecialFramework(folderName, out result) && !TryParseCommonFramework(folderName, out result)) { // assume this is unsupported unless we find a match result = UnsupportedFramework; var parts = RawParse(folderName); if (parts != null) { string framework = null; if (mappings.TryGetIdentifier(parts.Item1, out framework)) { var version = FrameworkConstants.EmptyVersion; if (parts.Item2 == null || mappings.TryGetVersion(parts.Item2, out version)) { var profileShort = parts.Item3; if (version.Major >= 5 && StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.Net, framework)) { // net should be treated as netcoreapp in 5.0 and later framework = FrameworkConstants.FrameworkIdentifiers.NetCoreApp; if (!string.IsNullOrEmpty(profileShort)) { bool validProfile = FrameworkConstants.FrameworkProfiles.Contains(profileShort); if (validProfile) { result = new NuGetFramework(framework, version, profileShort.ToLower()); } else { return(result); // with result == UnsupportedFramework } } else { result = new NuGetFramework(framework, version, string.Empty); } } else { string profile = null; if (!mappings.TryGetProfile(framework, profileShort, out profile)) { profile = profileShort ?? string.Empty; } if (StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.Portable, framework)) { IEnumerable <NuGetFramework> clientFrameworks = null; if (!mappings.TryGetPortableFrameworks(profileShort, out clientFrameworks)) { result = UnsupportedFramework; } else { var profileNumber = -1; if (mappings.TryGetPortableProfile(clientFrameworks, out profileNumber)) { var portableProfileNumber = FrameworkNameHelpers.GetPortableProfileNumberString(profileNumber); result = new NuGetFramework(framework, version, portableProfileNumber); } else { result = new NuGetFramework(framework, version, profileShort); } } } else { result = new NuGetFramework(framework, version, profile); } } } } } else { // If the framework was not recognized check if it is a deprecated framework NuGetFramework deprecated = null; if (TryParseDeprecatedFramework(folderName, out deprecated)) { result = deprecated; } } } return(result); }
/// <summary> /// Creates a NuGetFramework from a folder name using the given mappings. /// </summary> public static NuGetFramework ParseFolder(string folderName, IFrameworkNameProvider mappings) { if (folderName == null) { throw new ArgumentNullException(nameof(folderName)); } if (mappings == null) { throw new ArgumentNullException(nameof(mappings)); } if (folderName.IndexOf('%') > -1) { folderName = Uri.UnescapeDataString(folderName); } NuGetFramework result = null; // first check if we have a special or common framework if (!TryParseSpecialFramework(folderName, out result) && !TryParseCommonFramework(folderName, out result)) { // assume this is unsupported unless we find a match result = UnsupportedFramework; var parts = RawParse(folderName); if (parts != null) { string framework = null; if (mappings.TryGetIdentifier(parts.Item1, out framework)) { var version = FrameworkConstants.EmptyVersion; if (parts.Item2 == null || mappings.TryGetVersion(parts.Item2, out version)) { var profileShort = parts.Item3; if (version.Major >= 5 && (StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.Net, framework) || StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.NetCoreApp, framework) ) ) { // net should be treated as netcoreapp in 5.0 and later framework = FrameworkConstants.FrameworkIdentifiers.NetCoreApp; if (!string.IsNullOrEmpty(profileShort)) { // Find a platform version if it exists and yank it out var platformChars = profileShort; var versionStart = 0; while (versionStart < platformChars.Length && IsLetterOrDot(platformChars[versionStart])) { versionStart++; } string platform = versionStart > 0 ? profileShort.Substring(0, versionStart) : profileShort; string platformVersionString = versionStart > 0 ? profileShort.Substring(versionStart, profileShort.Length - versionStart) : null; // Parse the version if it's there. Version platformVersion = FrameworkConstants.EmptyVersion; if ((string.IsNullOrEmpty(platformVersionString) || mappings.TryGetPlatformVersion(platformVersionString, out platformVersion))) { result = new NuGetFramework(framework, version, platform ?? string.Empty, platformVersion ?? FrameworkConstants.EmptyVersion); } else { return(result); // with result == UnsupportedFramework } } else { result = new NuGetFramework(framework, version, string.Empty, FrameworkConstants.EmptyVersion); } } else { string profile = null; if (!mappings.TryGetProfile(framework, profileShort, out profile)) { profile = profileShort ?? string.Empty; } if (StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.Portable, framework)) { IEnumerable <NuGetFramework> clientFrameworks = null; if (!mappings.TryGetPortableFrameworks(profileShort, out clientFrameworks)) { result = UnsupportedFramework; } else { var profileNumber = -1; if (mappings.TryGetPortableProfile(clientFrameworks, out profileNumber)) { var portableProfileNumber = FrameworkNameHelpers.GetPortableProfileNumberString(profileNumber); result = new NuGetFramework(framework, version, portableProfileNumber); } else { result = new NuGetFramework(framework, version, profileShort); } } } else { result = new NuGetFramework(framework, version, profile); } } } } } else { // If the framework was not recognized check if it is a deprecated framework NuGetFramework deprecated = null; if (TryParseDeprecatedFramework(folderName, out deprecated)) { result = deprecated; } } } return(result); }
/// <summary> /// Creates a NuGetFramework from a folder name using the given mappings. /// </summary> public static NuGetFramework ParseFolder(string folderName, IFrameworkNameProvider mappings) { if (folderName == null) { throw new ArgumentNullException("folderName"); } if (folderName.IndexOf('%') > -1) { folderName = Uri.UnescapeDataString(folderName); } NuGetFramework result = null; // first check if we have a special or common framework if (!TryParseSpecialFramework(folderName, out result) && !TryParseCommonFramework(folderName, out result)) { // assume this is unsupported unless we find a match result = UnsupportedFramework; Tuple <string, string, string> parts = RawParse(folderName); if (parts != null) { string framework = null; if (mappings.TryGetIdentifier(parts.Item1, out framework)) { Version version = FrameworkConstants.EmptyVersion; if (parts.Item2 == null || mappings.TryGetVersion(parts.Item2, out version)) { string profileShort = parts.Item3; string profile = null; if (!mappings.TryGetProfile(framework, profileShort, out profile)) { profile = profileShort ?? string.Empty; } if (StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.Portable, framework)) { IEnumerable <NuGetFramework> clientFrameworks = null; mappings.TryGetPortableFrameworks(profileShort, out clientFrameworks); int profileNumber = -1; if (mappings.TryGetPortableProfile(clientFrameworks, out profileNumber)) { string portableProfileNumber = FrameworkNameHelpers.GetPortableProfileNumberString(profileNumber); result = new NuGetFramework(framework, version, portableProfileNumber); } else { // TODO: should this be unsupported? result = new NuGetFramework(framework, version, profileShort); } } else { result = new NuGetFramework(framework, version, profile); } } } } else { // If the framework was not recognized check if it is a deprecated framework NuGetFramework deprecated = null; if (TryParseDeprecatedFramework(folderName, out deprecated)) { result = deprecated; } } } return(result); }