private NETCoreSdkResolver.Result ResolveNETCoreSdkDirectory(SdkResolverContext context, string dotnetExeDir) { string globalJsonStartDir = Path.GetDirectoryName(context.SolutionFilePath ?? context.ProjectFilePath); var result = NETCoreSdkResolver.ResolveSdk(dotnetExeDir, globalJsonStartDir, _vsSettings.DisallowPrerelease()); string mostCompatible = result.ResolvedSdkDirectory; if (result.ResolvedSdkDirectory == null && result.GlobalJsonPath != null && context.IsRunningInVisualStudio) { result.FailedToResolveSDKSpecifiedInGlobalJson = true; // We need the SDK to be version 5 or higher to ensure that we generate a build error when we fail to resolve the SDK specified by global.json mostCompatible = GetMostCompatibleSdk(dotnetExeDir, context.MSBuildVersion, 5); } else if (result.ResolvedSdkDirectory != null && result.GlobalJsonPath == null && context.MSBuildVersion < GetMinimumMSBuildVersion(result.ResolvedSdkDirectory)) { mostCompatible = GetMostCompatibleSdk(dotnetExeDir, context.MSBuildVersion); } if (mostCompatible != null) { result.ResolvedSdkDirectory = mostCompatible; } return(result); }
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); }
private CompatibleSdkValue GetMostCompatibleSdks(string dotnetExeDirectory, Version msbuildVersion, int minimumSdkMajorVersion) { 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 (minimumSdkMajorVersion != 0 && Int32.TryParse(netcoreSdkVersion.Split('.')[0], out int sdkMajorVersion) && sdkMajorVersion < minimumSdkMajorVersion) { continue; } if (mostRecent == null) { mostRecent = netcoreSdkDir; } if (netcoreSdkVersion.IndexOf('-') < 0) { mostRecentNonPreview = netcoreSdkDir; break; } } return new CompatibleSdkValue(mostRecent, mostRecentNonPreview); })); }
public DotNetMSBuildSdkResolver(Func <string, string> getEnvironmentVariable, VSSettings vsSettings) { _getEnvironmentVariable = getEnvironmentVariable; _netCoreSdkResolver = new NETCoreSdkResolver(getEnvironmentVariable, vsSettings); }