Skip to content

Commit

Permalink
fix: relax .NET runtime version check (#443)
Browse files Browse the repository at this point in the history
Fixes #442.

* Relaxes the .NET runtime version check to only require the .NET
Runtime (instead of ASP.NET Core too), and to permit versions later than
6.0.x.
* Make the version check error message more concise, in order to reduce
the likelihood that VS Code hides the notification (due to the message
being too long to fit on screen).
  • Loading branch information
alex-chew authored Oct 10, 2023
1 parent 768c1c3 commit a40bbe8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export namespace ConfigurationConstants {

export namespace DotnetConstants {
export const ExecutableName = 'dotnet';
export const SupportedRuntimesPattern = /Microsoft\.AspNetCore\.App\s*[56]\.0/i;
export const SupportedRuntimesPattern = /Microsoft\.NETCore\.App\s*((\d+)\.\d+\.\d+)/ig;
export const SupportedRuntimesMinVersion = 5;
}

export namespace LanguageServerConstants {
Expand Down
15 changes: 13 additions & 2 deletions src/dotnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ export async function checkSupportedDotnetVersion(): Promise<string | undefined>
return dotnetExecutable + Messages.Dotnet.IsNotAnExecutableFile;
}
const { stdout } = await execFileAsync(dotnetExecutable, [ ListRuntimesArg ]);
return DotnetConstants.SupportedRuntimesPattern.test(stdout) ? undefined
: dotnetExecutable + Messages.Dotnet.NotASupportedDotnetInstallation + stdout;
const runtimeVersions = [ ...stdout.matchAll(DotnetConstants.SupportedRuntimesPattern) ]
.map(match => {
const full = match[1];
const major = parseInt(match[2], 10);
return { full, major };
});
if(runtimeVersions.find(({ major }) => major >= DotnetConstants.SupportedRuntimesMinVersion) !== undefined) {
return undefined;
}
const runtimeVersionsStr = runtimeVersions.length === 0
? ' no installed versions'
: runtimeVersions.map(({ full }) => full).join(', ');
return dotnetExecutable + Messages.Dotnet.NotASupportedDotnetInstallation + runtimeVersionsStr;
} catch(error: unknown) {
const errorMsg = `Error invoking ${dotnetExecutable} ${ListRuntimesArg}: ${error}`;
console.error(errorMsg);
Expand Down
6 changes: 3 additions & 3 deletions src/ui/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export namespace Messages {

export namespace Dotnet {
export const IsNotAnExecutableFile = ' is not an executable dotnet file.';
export const NotASupportedDotnetInstallation = ' is not a compatible dotnet file. Dafny requires the ASP.NET Core Runtime 5.0 or 6.0, got ';
export const FailedDotnetExecution = 'Failed to execute dotnet. Dafny requires the ASP.NET Core Runtime 5.0 or 6.0.';
export const NoCompatibleInstallation = 'No compatible dotnet runtime found. Dafny requires the ASP.NET Core Runtime 5.0 or 6.0.';
export const NotASupportedDotnetInstallation = ' is not a compatible dotnet file. Dafny requires the .NET Runtime 5.0 or greater, found ';
export const FailedDotnetExecution = 'Failed to execute dotnet. Dafny requires the .NET Runtime 5.0 or greater.';
export const NoCompatibleInstallation = 'No compatible dotnet runtime found. Dafny requires the .NET Runtime 5.0 or greater.';
export const ChangeConfiguration = 'Configure the absolute path to dotnet';
export const VisitDownload = 'Get .NET SDK';
export const DownloadUri = 'https://dotnet.microsoft.com/download/dotnet/6.0';
Expand Down

0 comments on commit a40bbe8

Please sign in to comment.