mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Error out for unsupported dotnet versions for sql db projects (#16428)
* Merge conflict resolution * Throw error for unsupported versions of Dotnet * Fix for darwin * Fix for all platforms * Address comments * Fix extensionsGaller.json * Address comments * Update default installation path for linux * Fix test * Revert default installation location change for Linux * Address comments * Removed extra try-catch block
This commit is contained in:
@@ -251,6 +251,15 @@ export const externalStreamingJobFriendlyName = localize('externalStreamingJobFr
|
|||||||
export const preDeployScriptFriendlyName = localize('preDeployScriptFriendlyName', "Script.PreDeployment");
|
export const preDeployScriptFriendlyName = localize('preDeployScriptFriendlyName', "Script.PreDeployment");
|
||||||
export const postDeployScriptFriendlyName = localize('postDeployScriptFriendlyName', "Script.PostDeployment");
|
export const postDeployScriptFriendlyName = localize('postDeployScriptFriendlyName', "Script.PostDeployment");
|
||||||
|
|
||||||
|
// Build
|
||||||
|
|
||||||
|
export const NetCoreInstallationConfirmation: string = localize('sqlDatabaseProjects.NetCoreInstallationConfirmation', "The .NET Core SDK cannot be located. Project build will not work. Please install .NET Core SDK version 3.1 or update the .NET Core SDK location in settings if already installed.");
|
||||||
|
export function NetCoreSupportedVersionInstallationConfirmation(installedVersion: string) { return localize('sqlDatabaseProjects.NetCoreSupportedVersionInstallationConfirmation', "Currently installed .NET Core SDK version is {0}, which is not supported. Project build will not work. Please install .NET Core SDK version 3.1 or update the .NET Core SDK supported version location in settings if already installed.", installedVersion); }
|
||||||
|
export const UpdateNetCoreLocation: string = localize('sqlDatabaseProjects.UpdateNetCoreLocation', "Update Location");
|
||||||
|
export const InstallNetCore: string = localize('sqlDatabaseProjects.InstallNetCore', "Install");
|
||||||
|
export const DoNotAskAgain: string = localize('sqlDatabaseProjects.doNotAskAgain', "Don't Ask Again");
|
||||||
|
export const projectsOutputChannel = localize('sqlDatabaseProjects.outputChannel', "Database Projects");
|
||||||
|
|
||||||
// SqlProj file XML names
|
// SqlProj file XML names
|
||||||
export const ItemGroup = 'ItemGroup';
|
export const ItemGroup = 'ItemGroup';
|
||||||
export const Build = 'Build';
|
export const Build = 'Build';
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import * as fs from 'fs';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as sinon from 'sinon';
|
import * as sinon from 'sinon';
|
||||||
import { NetCoreTool, DBProjectConfigurationKey, NetCoreInstallLocationKey, NextCoreNonWindowsDefaultPath } from '../tools/netcoreTool';
|
import { NetCoreTool, DBProjectConfigurationKey, NetCoreInstallLocationKey, NetCoreNonWindowsDefaultPath } from '../tools/netcoreTool';
|
||||||
import { getQuotedPath } from '../common/utils';
|
import { getQuotedPath } from '../common/utils';
|
||||||
import { isNullOrUndefined } from 'util';
|
import { isNullOrUndefined } from 'util';
|
||||||
import { generateTestFolderPath } from './testUtils';
|
import { generateTestFolderPath } from './testUtils';
|
||||||
@@ -47,7 +47,7 @@ describe('NetCoreTool: Net core tests', function (): void {
|
|||||||
|
|
||||||
if (os.platform() === 'linux' || os.platform() === 'darwin') {
|
if (os.platform() === 'linux' || os.platform() === 'darwin') {
|
||||||
//check that path should start with /usr/local/share
|
//check that path should start with /usr/local/share
|
||||||
let result = isNullOrUndefined(netcoreTool.netcoreInstallLocation) || netcoreTool.netcoreInstallLocation.toLowerCase().startsWith(NextCoreNonWindowsDefaultPath);
|
let result = isNullOrUndefined(netcoreTool.netcoreInstallLocation) || netcoreTool.netcoreInstallLocation.toLowerCase().startsWith(NetCoreNonWindowsDefaultPath);
|
||||||
should(result).true('dotnet is either not present or in /usr/local/share by default');
|
should(result).true('dotnet is either not present or in /usr/local/share by default');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,26 +3,34 @@
|
|||||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
import * as vscode from 'vscode';
|
import * as child_process from 'child_process';
|
||||||
import * as path from 'path';
|
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
|
import * as path from 'path';
|
||||||
import * as cp from 'promisify-child-process';
|
import * as cp from 'promisify-child-process';
|
||||||
import * as nls from 'vscode-nls';
|
import * as semver from 'semver';
|
||||||
import { isNullOrUndefined } from 'util';
|
import { isNullOrUndefined } from 'util';
|
||||||
|
import * as vscode from 'vscode';
|
||||||
|
import * as nls from 'vscode-nls';
|
||||||
|
import { DoNotAskAgain, InstallNetCore, NetCoreInstallationConfirmation, NetCoreSupportedVersionInstallationConfirmation, projectsOutputChannel, UpdateNetCoreLocation } from '../common/constants';
|
||||||
import * as utils from '../common/utils';
|
import * as utils from '../common/utils';
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
export const DBProjectConfigurationKey: string = 'sqlDatabaseProjects';
|
export const DBProjectConfigurationKey: string = 'sqlDatabaseProjects';
|
||||||
export const NetCoreInstallLocationKey: string = 'netCoreSDKLocation';
|
export const NetCoreInstallLocationKey: string = 'netCoreSDKLocation';
|
||||||
export const NetCoreDoNotAskAgainKey: string = 'netCoreDoNotAsk';
|
export const NetCoreDoNotAskAgainKey: string = 'netCoreDoNotAsk';
|
||||||
export const NextCoreNonWindowsDefaultPath = '/usr/local/share';
|
export const NetCoreNonWindowsDefaultPath = '/usr/local/share';
|
||||||
export const NetCoreInstallationConfirmation: string = localize('sqlDatabaseProjects.NetCoreInstallationConfirmation', "The .NET Core SDK cannot be located. Project build will not work. Please install .NET Core SDK version 3.1 or update the .Net Core SDK location in settings if already installed.");
|
export const winPlatform: string = 'win32';
|
||||||
export const UpdateNetCoreLocation: string = localize('sqlDatabaseProjects.UpdateNetCoreLocation', "Update Location");
|
export const macPlatform: string = 'darwin';
|
||||||
export const InstallNetCore: string = localize('sqlDatabaseProjects.InstallNetCore', "Install");
|
export const linuxPlatform: string = 'linux';
|
||||||
export const DoNotAskAgain: string = localize('sqlDatabaseProjects.doNotAskAgain', "Don't Ask Again");
|
export const minSupportedNetCoreVersion: string = '3.1.0';
|
||||||
|
|
||||||
|
export const enum netCoreInstallState {
|
||||||
|
netCoreNotPresent,
|
||||||
|
netCoreVersionNotSupported,
|
||||||
|
netCoreVersionSupported
|
||||||
|
}
|
||||||
|
|
||||||
const projectsOutputChannel = localize('sqlDatabaseProjects.outputChannel', "Database Projects");
|
|
||||||
const dotnet = os.platform() === 'win32' ? 'dotnet.exe' : 'dotnet';
|
const dotnet = os.platform() === 'win32' ? 'dotnet.exe' : 'dotnet';
|
||||||
|
|
||||||
export interface DotNetCommandOptions {
|
export interface DotNetCommandOptions {
|
||||||
@@ -35,17 +43,33 @@ export interface DotNetCommandOptions {
|
|||||||
export class NetCoreTool {
|
export class NetCoreTool {
|
||||||
|
|
||||||
private static _outputChannel: vscode.OutputChannel = vscode.window.createOutputChannel(projectsOutputChannel);
|
private static _outputChannel: vscode.OutputChannel = vscode.window.createOutputChannel(projectsOutputChannel);
|
||||||
|
private osPlatform: string = os.platform();
|
||||||
|
private netCoreSdkInstalledVersion: string | undefined;
|
||||||
|
private netCoreInstallState: netCoreInstallState = netCoreInstallState.netCoreVersionSupported;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method presents the installation dialog for .NET Core, if not already present/supported
|
||||||
|
* @returns True if .NET version was found and is supported
|
||||||
|
* False if .NET version isn't present or present but not supported
|
||||||
|
*/
|
||||||
public async findOrInstallNetCore(): Promise<boolean> {
|
public async findOrInstallNetCore(): Promise<boolean> {
|
||||||
if (!this.isNetCoreInstallationPresent && vscode.workspace.getConfiguration(DBProjectConfigurationKey)[NetCoreDoNotAskAgainKey] !== true) {
|
if ((!this.isNetCoreInstallationPresent || !await this.isNetCoreVersionSupported())) {
|
||||||
await this.showInstallDialog();
|
if (vscode.workspace.getConfiguration(DBProjectConfigurationKey)[NetCoreDoNotAskAgainKey] !== true) {
|
||||||
|
await this.showInstallDialog();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
this.netCoreInstallState = netCoreInstallState.netCoreVersionSupported;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async showInstallDialog(): Promise<void> {
|
public async showInstallDialog(): Promise<void> {
|
||||||
let result = await vscode.window.showInformationMessage(NetCoreInstallationConfirmation, UpdateNetCoreLocation, InstallNetCore, DoNotAskAgain);
|
let result;
|
||||||
|
if (this.netCoreInstallState === netCoreInstallState.netCoreNotPresent) {
|
||||||
|
result = await vscode.window.showInformationMessage(NetCoreInstallationConfirmation, UpdateNetCoreLocation, InstallNetCore, DoNotAskAgain);
|
||||||
|
} else {
|
||||||
|
result = await vscode.window.showInformationMessage(NetCoreSupportedVersionInstallationConfirmation(this.netCoreSdkInstalledVersion!), UpdateNetCoreLocation, InstallNetCore, DoNotAskAgain);
|
||||||
|
}
|
||||||
|
|
||||||
if (result === UpdateNetCoreLocation) {
|
if (result === UpdateNetCoreLocation) {
|
||||||
//open settings
|
//open settings
|
||||||
@@ -60,8 +84,12 @@ export class NetCoreTool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private get isNetCoreInstallationPresent(): Boolean {
|
private get isNetCoreInstallationPresent(): boolean {
|
||||||
return (!isNullOrUndefined(this.netcoreInstallLocation) && fs.existsSync(this.netcoreInstallLocation));
|
const netCoreInstallationPresent = (!isNullOrUndefined(this.netcoreInstallLocation) && fs.existsSync(this.netcoreInstallLocation));
|
||||||
|
if (!netCoreInstallationPresent) {
|
||||||
|
this.netCoreInstallState = netCoreInstallState.netCoreNotPresent;
|
||||||
|
}
|
||||||
|
return netCoreInstallationPresent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get netcoreInstallLocation(): string {
|
public get netcoreInstallLocation(): string {
|
||||||
@@ -70,15 +98,16 @@ export class NetCoreTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private get defaultLocalInstallLocationByDistribution(): string | undefined {
|
private get defaultLocalInstallLocationByDistribution(): string | undefined {
|
||||||
const osPlatform: string = os.platform();
|
switch (this.osPlatform) {
|
||||||
return (osPlatform === 'win32') ? this.defaultWindowsLocation :
|
case winPlatform: return this.defaultWindowsLocation;
|
||||||
(osPlatform === 'darwin' || osPlatform === 'linux') ? this.defaultnonWindowsLocation :
|
case macPlatform:
|
||||||
undefined;
|
case linuxPlatform: return this.defaultnonWindowsLocation;
|
||||||
|
default: return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private get defaultnonWindowsLocation(): string | undefined {
|
private get defaultnonWindowsLocation(): string | undefined {
|
||||||
const defaultNonWindowsInstallLocation = NextCoreNonWindowsDefaultPath; //default folder for net core sdk
|
return this.getDotnetPathIfPresent(NetCoreNonWindowsDefaultPath) || //default folder for net core sdk
|
||||||
return this.getDotnetPathIfPresent(defaultNonWindowsInstallLocation) ||
|
|
||||||
this.getDotnetPathIfPresent(os.homedir()) ||
|
this.getDotnetPathIfPresent(os.homedir()) ||
|
||||||
undefined;
|
undefined;
|
||||||
}
|
}
|
||||||
@@ -96,13 +125,67 @@ export class NetCoreTool {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function checks if the installed dotnet version is atleast minSupportedNetCoreVersion.
|
||||||
|
* Versions lower than minSupportedNetCoreVersion aren't supported for building projects.
|
||||||
|
* Returns: True if installed dotnet version is supported, false otherwise.
|
||||||
|
* Undefined if dotnet isn't installed.
|
||||||
|
*/
|
||||||
|
private async isNetCoreVersionSupported(): Promise<boolean | undefined> {
|
||||||
|
try {
|
||||||
|
const spawn = child_process.spawn;
|
||||||
|
let child: child_process.ChildProcessWithoutNullStreams;
|
||||||
|
let isSupported: boolean | undefined = undefined;
|
||||||
|
const stdoutBuffers: Buffer[] = [];
|
||||||
|
|
||||||
|
child = spawn('dotnet --version', [], {
|
||||||
|
shell: true
|
||||||
|
});
|
||||||
|
|
||||||
|
child.stdout.on('data', (b: Buffer) => stdoutBuffers.push(b));
|
||||||
|
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
child.on('exit', () => {
|
||||||
|
this.netCoreSdkInstalledVersion = Buffer.concat(stdoutBuffers).toString('utf8').trim();
|
||||||
|
|
||||||
|
if (semver.gte(this.netCoreSdkInstalledVersion, minSupportedNetCoreVersion)) { // Net core version greater than or equal to minSupportedNetCoreVersion are supported for Build
|
||||||
|
isSupported = true;
|
||||||
|
} else {
|
||||||
|
isSupported = false;
|
||||||
|
}
|
||||||
|
resolve({ stdout: this.netCoreSdkInstalledVersion });
|
||||||
|
});
|
||||||
|
child.on('error', (err) => {
|
||||||
|
console.log(err);
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isSupported) {
|
||||||
|
this.netCoreInstallState = netCoreInstallState.netCoreVersionSupported;
|
||||||
|
} else {
|
||||||
|
this.netCoreInstallState = netCoreInstallState.netCoreVersionNotSupported;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isSupported;
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
this.netCoreInstallState = netCoreInstallState.netCoreVersionNotSupported;
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async runDotnetCommand(options: DotNetCommandOptions): Promise<string> {
|
public async runDotnetCommand(options: DotNetCommandOptions): Promise<string> {
|
||||||
if (options && options.commandTitle !== undefined && options.commandTitle !== null) {
|
if (options && options.commandTitle !== undefined && options.commandTitle !== null) {
|
||||||
NetCoreTool._outputChannel.appendLine(`\t[ ${options.commandTitle} ]`);
|
NetCoreTool._outputChannel.appendLine(`\t[ ${options.commandTitle} ]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(await this.findOrInstallNetCore())) {
|
if (!(await this.findOrInstallNetCore())) {
|
||||||
throw new Error(NetCoreInstallationConfirmation);
|
if (this.netCoreInstallState === netCoreInstallState.netCoreNotPresent) {
|
||||||
|
throw new Error(NetCoreInstallationConfirmation);
|
||||||
|
} else {
|
||||||
|
throw new Error(NetCoreSupportedVersionInstallationConfirmation(this.netCoreSdkInstalledVersion!));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dotnetPath = utils.getQuotedPath(path.join(this.netcoreInstallLocation, dotnet));
|
const dotnetPath = utils.getQuotedPath(path.join(this.netcoreInstallLocation, dotnet));
|
||||||
|
|||||||
Reference in New Issue
Block a user