Beispiel #1
0
        private NETCoreSdkResolver.Result ResolveNETCoreSdkDirectory(SdkResolverContext context, string dotnetExeDir)
        {
            string globalJsonStartDir = Path.GetDirectoryName(context.SolutionFilePath ?? context.ProjectFilePath);
            var    result             = NETCoreSdkResolver.ResolveSdk(dotnetExeDir, globalJsonStartDir, _vsSettings.DisallowPrerelease());

            if (result.ResolvedSdkDirectory != null &&
                result.GlobalJsonPath == null &&
                context.MSBuildVersion < GetMinimumMSBuildVersion(result.ResolvedSdkDirectory))
            {
                string mostCompatible = GetMostCompatibleSdk(dotnetExeDir, context.MSBuildVersion);

                if (mostCompatible != null)
                {
                    result.ResolvedSdkDirectory = mostCompatible;
                }
            }

            return(result);
        }
Beispiel #2
0
        private CompatibleSdkValue GetMostCompatibleSdks(string dotnetExeDirectory, Version msbuildVersion)
        {
            return(s_compatibleSdks.GetOrAdd(
                       new CompatibleSdkKey(dotnetExeDirectory, msbuildVersion),
                       key =>
            {
                string mostRecent = null;
                string mostRecentNonPreview = null;

                string[] availableSdks = NETCoreSdkResolver.GetAvailableSdks(key.DotnetExeDirectory);
                for (int i = availableSdks.Length - 1; i >= 0; i--)
                {
                    string netcoreSdkDir = availableSdks[i];
                    string netcoreSdkVersion = new DirectoryInfo(netcoreSdkDir).Name;
                    Version minimumMSBuildVersion = GetMinimumMSBuildVersion(netcoreSdkDir);

                    if (key.MSBuildVersion < minimumMSBuildVersion)
                    {
                        continue;
                    }

                    if (mostRecent == null)
                    {
                        mostRecent = netcoreSdkDir;
                    }

                    if (netcoreSdkVersion.IndexOf('-') < 0)
                    {
                        mostRecentNonPreview = netcoreSdkDir;
                        break;
                    }
                }

                return new CompatibleSdkValue(mostRecent, mostRecentNonPreview);
            }));
        }