in src/NuGet.Core/NuGet.Frameworks/NuGetFrameworkFactory.cs [254:375]
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;
// 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)
{
if (mappings.TryGetIdentifier(parts.Item1, out string? framework))
{
var version = FrameworkConstants.EmptyVersion;
if (parts.Item2 == null
|| mappings.TryGetVersion(parts.Item2, out version))
{
string 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
{
if (!mappings.TryGetProfile(framework, profileShort, out string? profile))
{
profile = profileShort ?? string.Empty;
}
if (StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.Portable, framework))
{
if (!mappings.TryGetPortableFrameworks(profileShort!, out IEnumerable<NuGetFramework>? 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
if (TryParseDeprecatedFramework(folderName, out NuGetFramework? deprecated))
{
result = deprecated;
}
}
}
return result;
}