Skip to content

Commit

Permalink
Correct matching for prerelease .NET versions. Fixes dotnet#4931.
Browse files Browse the repository at this point in the history
  • Loading branch information
333fred committed Dec 10, 2021
1 parent 59be46d commit aa514a6
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/omnisharp/OmniSharpDotnetResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,29 @@ export class OmniSharpDotnetResolver implements IHostExecutableResolver {
throw new Error(`Unable to read dotnet version information. Error ${result.stderr}`);
}

const segments = result.stdout.split('.').map(str => Number.parseInt(str));
if (segments.length != 3) {
const segments: number[] = [];
const stdoutSplit = result.stdout.split('.');
if (stdoutSplit.length != 3) {
throw new Error(`Unknown result output from 'dotnet --version'. Received ${result.stdout}`);
}

let isPrerelease = false;

for (let i = 0; i < 3; i++) {
let segment = stdoutSplit[i];
if (i === 2) {
const dashIndex = segment.indexOf('-');
if (dashIndex !== -1) {
isPrerelease = true;
segment = segment.substring(0, dashIndex);
}
}

segments.push(Number.parseInt(segment));
}

result.stdout.split('.').map(str => Number.parseInt(str));

if (this.versionPartIsGreaterThanMinimum(segments[0], minimumDotnetMajor, result.stdout)
|| this.versionPartIsGreaterThanMinimum(segments[1], minimumDotnetMinor, result.stdout)) {
return {
Expand All @@ -48,7 +66,9 @@ export class OmniSharpDotnetResolver implements IHostExecutableResolver {
};
}

this.versionPartIsGreaterThanMinimum(segments[2], minimumDotnetPatch, result.stdout);
// If the found SDK is a pre-release version of .NET, then we need to ensure that it's a _higher_ patch version than the required
// minimum, not a prerelease version of the required minimum.
this.versionPartIsGreaterThanMinimum(segments[2], minimumDotnetPatch, result.stdout, /*disallowExactMatch*/ isPrerelease);

return {
version: result.stdout,
Expand All @@ -57,8 +77,8 @@ export class OmniSharpDotnetResolver implements IHostExecutableResolver {
};
}

private versionPartIsGreaterThanMinimum(actualVersion: number, minimumRequired: number, foundVersion: string): boolean {
if (actualVersion < minimumRequired) {
private versionPartIsGreaterThanMinimum(actualVersion: number, minimumRequired: number, foundVersion: string, disallowExactMatch: boolean = false): boolean {
if (actualVersion < minimumRequired || (disallowExactMatch && actualVersion === minimumRequired)) {
throw new Error(`Found dotnet version ${foundVersion}. Minimum required version is ${minimumDotnetMajor}.${minimumDotnetMinor}.${minimumDotnetPatch}.`);
}

Expand Down

0 comments on commit aa514a6

Please sign in to comment.