mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 17:22:20 -05:00
Warning when .NET 6 SDK is detected (#17422)
* Check for max supported version * Separate dialog for downgrade warning * Address PR comments * Use markdown link * Update warning message
This commit is contained in:
@@ -11,7 +11,7 @@ import * as semver from 'semver';
|
||||
import { isNullOrUndefined } from 'util';
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { DoNotAskAgain, Install, NetCoreInstallationConfirmation, NetCoreSupportedVersionInstallationConfirmation, UpdateNetCoreLocation } from '../common/constants';
|
||||
import { DoNotAskAgain, DoNotShowAgain, Install, NetCoreInstallationConfirmation, NetCoreSupportedVersionInstallationConfirmation, NetCoreVersionDowngradeConfirmation, UpdateNetCoreLocation } from '../common/constants';
|
||||
import * as utils from '../common/utils';
|
||||
import { ShellCommandOptions, ShellExecutionHelper } from './shellExecutionHelper';
|
||||
const localize = nls.loadMessageBundle();
|
||||
@@ -19,16 +19,19 @@ const localize = nls.loadMessageBundle();
|
||||
export const DBProjectConfigurationKey: string = 'sqlDatabaseProjects';
|
||||
export const NetCoreInstallLocationKey: string = 'netCoreSDKLocation';
|
||||
export const NetCoreDoNotAskAgainKey: string = 'netCoreDoNotAsk';
|
||||
export const NetCoreDowngradeDoNotShowAgainKey: string = 'netCoreDowngradeDoNotShow';
|
||||
export const NetCoreNonWindowsDefaultPath = '/usr/local/share';
|
||||
export const winPlatform: string = 'win32';
|
||||
export const macPlatform: string = 'darwin';
|
||||
export const linuxPlatform: string = 'linux';
|
||||
export const minSupportedNetCoreVersion: string = '3.1.0';
|
||||
export const maxSupportedNetCoreVersionCutoff: string = '6.0.0'; // un-set this to allow latest
|
||||
|
||||
export const enum netCoreInstallState {
|
||||
netCoreNotPresent,
|
||||
netCoreVersionNotSupported,
|
||||
netCoreVersionSupported
|
||||
netCoreVersionSupported,
|
||||
netCoreVersionTooHigh
|
||||
}
|
||||
|
||||
const dotnet = os.platform() === 'win32' ? 'dotnet.exe' : 'dotnet';
|
||||
@@ -46,8 +49,10 @@ export class NetCoreTool extends ShellExecutionHelper {
|
||||
*/
|
||||
public async findOrInstallNetCore(): Promise<boolean> {
|
||||
if ((!this.isNetCoreInstallationPresent || !await this.isNetCoreVersionSupported())) {
|
||||
if (vscode.workspace.getConfiguration(DBProjectConfigurationKey)[NetCoreDoNotAskAgainKey] !== true) {
|
||||
if (this.netCoreInstallState === netCoreInstallState.netCoreVersionSupported && vscode.workspace.getConfiguration(DBProjectConfigurationKey)[NetCoreDoNotAskAgainKey] !== true) {
|
||||
void this.showInstallDialog(); // Removing await so that Build and extension load process doesn't wait on user input
|
||||
} else if (this.netCoreInstallState === netCoreInstallState.netCoreVersionTooHigh && vscode.workspace.getConfiguration(DBProjectConfigurationKey)[NetCoreDowngradeDoNotShowAgainKey] !== true) {
|
||||
void this.showDowngradeDialog();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -80,6 +85,15 @@ export class NetCoreTool extends ShellExecutionHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public async showDowngradeDialog(): Promise<void> {
|
||||
const result = await vscode.window.showErrorMessage(NetCoreVersionDowngradeConfirmation(this.netCoreSdkInstalledVersion!), DoNotShowAgain);
|
||||
|
||||
if (result === DoNotShowAgain) {
|
||||
const config = vscode.workspace.getConfiguration(DBProjectConfigurationKey);
|
||||
await config.update(NetCoreDowngradeDoNotShowAgainKey, true, vscode.ConfigurationTarget.Global);
|
||||
}
|
||||
}
|
||||
|
||||
private get isNetCoreInstallationPresent(): boolean {
|
||||
const netCoreInstallationPresent = (!isNullOrUndefined(this.netcoreInstallLocation) && fs.existsSync(this.netcoreInstallLocation));
|
||||
if (!netCoreInstallationPresent) {
|
||||
@@ -122,8 +136,8 @@ export class NetCoreTool extends ShellExecutionHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks if the installed dotnet version is atleast minSupportedNetCoreVersion.
|
||||
* Versions lower than minSupportedNetCoreVersion aren't supported for building projects.
|
||||
* This function checks if the installed dotnet version is between minSupportedNetCoreVersion (inclusive) and maxSupportedNetCoreVersionCutoff (exclusive).
|
||||
* When maxSupportedNetCoreVersionCutoff is not set, the latest dotnet version is assumed to be supported and only the min version is checked.
|
||||
* Returns: True if installed dotnet version is supported, false otherwise.
|
||||
* Undefined if dotnet isn't installed.
|
||||
*/
|
||||
@@ -131,7 +145,7 @@ export class NetCoreTool extends ShellExecutionHelper {
|
||||
try {
|
||||
const spawn = child_process.spawn;
|
||||
let child: child_process.ChildProcessWithoutNullStreams;
|
||||
let isSupported: boolean | undefined = undefined;
|
||||
let installState: netCoreInstallState = netCoreInstallState.netCoreVersionSupported;
|
||||
const stdoutBuffers: Buffer[] = [];
|
||||
|
||||
child = spawn('dotnet --version', [], {
|
||||
@@ -145,10 +159,21 @@ export class NetCoreTool extends ShellExecutionHelper {
|
||||
this.netCoreSdkInstalledVersion = Buffer.concat(stdoutBuffers).toString('utf8').trim();
|
||||
|
||||
try {
|
||||
if (semver.gte(this.netCoreSdkInstalledVersion, minSupportedNetCoreVersion)) { // Net core version greater than or equal to minSupportedNetCoreVersion are supported for Build
|
||||
isSupported = true;
|
||||
// minSupportedDotnetVersion <= supported version < maxSupportedDotnetVersion
|
||||
if (semver.gte(this.netCoreSdkInstalledVersion, minSupportedNetCoreVersion)) {
|
||||
// If maxSupportedNetCoreVersionCutoff is not set, the latest .NET version is allowed
|
||||
if (maxSupportedNetCoreVersionCutoff) {
|
||||
if (semver.lt(this.netCoreSdkInstalledVersion, maxSupportedNetCoreVersionCutoff)) {
|
||||
installState = netCoreInstallState.netCoreVersionSupported;
|
||||
} else {
|
||||
installState = netCoreInstallState.netCoreVersionTooHigh;
|
||||
}
|
||||
} else {
|
||||
installState = netCoreInstallState.netCoreVersionSupported;
|
||||
}
|
||||
} else {
|
||||
isSupported = false;
|
||||
// .NET version is too low
|
||||
installState = netCoreInstallState.netCoreVersionNotSupported;
|
||||
}
|
||||
resolve({ stdout: this.netCoreSdkInstalledVersion });
|
||||
} catch (err) {
|
||||
@@ -163,13 +188,8 @@ export class NetCoreTool extends ShellExecutionHelper {
|
||||
});
|
||||
});
|
||||
|
||||
if (isSupported) {
|
||||
this.netCoreInstallState = netCoreInstallState.netCoreVersionSupported;
|
||||
} else {
|
||||
this.netCoreInstallState = netCoreInstallState.netCoreVersionNotSupported;
|
||||
}
|
||||
|
||||
return isSupported;
|
||||
this.netCoreInstallState = installState;
|
||||
return installState === netCoreInstallState.netCoreVersionSupported;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
this.netCoreInstallState = netCoreInstallState.netCoreNotPresent;
|
||||
@@ -185,6 +205,8 @@ export class NetCoreTool extends ShellExecutionHelper {
|
||||
if (!(await this.findOrInstallNetCore())) {
|
||||
if (this.netCoreInstallState === netCoreInstallState.netCoreNotPresent) {
|
||||
throw new DotNetError(NetCoreInstallationConfirmation);
|
||||
} else if (this.netCoreInstallState === netCoreInstallState.netCoreVersionTooHigh && vscode.workspace.getConfiguration(DBProjectConfigurationKey)[NetCoreDowngradeDoNotShowAgainKey] === true) {
|
||||
// Assume user has used global.json to override SDK version and proceed with build as is
|
||||
} else {
|
||||
throw new DotNetError(NetCoreSupportedVersionInstallationConfirmation(this.netCoreSdkInstalledVersion!));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user