private static NuGetVersionSpecification ParseVersion(string version)
            {
                if (!NuGetVersionSpecification.TryParse(version, out NuGetVersionSpecification? sdkVersion))
                {
                    throw new ConfigurationException(string.Format(LocalizableStrings.SdkConstraint_Error_InvalidVersion, version));
                }

                return(sdkVersion !);
            }
 internal static bool TryParse(string value, out NuGetVersionSpecification?version)
 {
     if (NuGetVersion.TryParse(value, out NuGetVersion nuGetVersion))
     {
         version = new NuGetVersionSpecification(nuGetVersion);
         return(true);
     }
     version = null;
     return(false);
 }
 private SdkVersionConstraint(
     IEngineEnvironmentSettings environmentSettings,
     ITemplateConstraintFactory factory,
     NuGetVersionSpecification currentSdkVersion,
     IEnumerable <NuGetVersionSpecification> installedSdkVersions,
     Func <IReadOnlyList <string>, IReadOnlyList <string>, string> remedySuggestionFactory)
     : base(environmentSettings, factory)
 {
     _currentSdkVersion       = currentSdkVersion;
     _installedSdkVersion     = installedSdkVersions.ToList();
     _remedySuggestionFactory = remedySuggestionFactory;
 }
            ExtractInstalledSdkVersionAsync(IEnumerable <ISdkInfoProvider> sdkInfoProviders, CancellationToken cancellationToken)
            {
                List <ISdkInfoProvider> providers = sdkInfoProviders.ToList();

                if (providers.Count == 0)
                {
                    throw new ConfigurationException(LocalizableStrings.SdkConstraint_Error_MissingProvider);
                }

                if (providers.Count > 1)
                {
                    throw new ConfigurationException(
                              string.Format(LocalizableStrings.SdkConstraint_Error_MismatchedProviders, providers.Select(p => p.Id).ToCsvString()));
                }

                cancellationToken.ThrowIfCancellationRequested();
                string version = await providers[0].GetCurrentVersionAsync(cancellationToken).ConfigureAwait(false);
                NuGetVersionSpecification currentSdkVersion = ParseVersion(version);

                cancellationToken.ThrowIfCancellationRequested();
                IEnumerable <NuGetVersionSpecification> versions = (await providers[0].GetInstalledVersionsAsync(cancellationToken).ConfigureAwait(false)).Select(ParseVersion);

                return(currentSdkVersion, versions, providers[0].ProvideConstraintRemedySuggestion);