Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vscode): Update calls to check for dotnet installation #4621

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ import {
updateFunctionsSDKVersion,
writeBuildFileToDisk,
} from '../../../../utils/codeless/updateBuildFile';
import { getFramework, validateDotnetInstalled } from '../../../../utils/dotnet/executeDotnetTemplateCommand';
import { getFramework } from '../../../../utils/dotnet/executeDotnetTemplateCommand';
import { writeFormattedJson } from '../../../../utils/fs';
import { parseJson } from '../../../../utils/parseJson';
import { WorkflowCreateStepBase } from '../../../createCodeless/createCodelessSteps/WorkflowCreateStepBase';
import type { IActionContext } from '@microsoft/vscode-azext-utils';
import { DialogResponses, nonNullProp, parseError } from '@microsoft/vscode-azext-utils';
import { WorkflowProjectType, MismatchBehavior } from '@microsoft/vscode-extension-logic-apps';
import type { IFunctionWizardContext, IWorkflowTemplate, IHostJsonV2, StandardApp } from '@microsoft/vscode-extension-logic-apps';
import * as fse from 'fs-extra';
import * as path from 'path';
import type { MessageItem } from 'vscode';
import { validateDotNetIsInstalled } from '../../../dotnet/validateDotNetInstalled';

// This class creates a new workflow for a codeless Azure Function project
export class CodelessFunctionWorkflow extends WorkflowCreateStepBase<IFunctionWizardContext> {
Expand All @@ -42,9 +42,13 @@ export class CodelessFunctionWorkflow extends WorkflowCreateStepBase<IFunctionWi
}

// Static method that creates a new instance of the CodelessFunctionProjectWorkflowCreateStep class and returns it
public static async createStep(context: IActionContext): Promise<CodelessFunctionWorkflow> {
public static async createStep(context: IFunctionWizardContext): Promise<CodelessFunctionWorkflow> {
// Ensure that the .NET Core SDK is installed on the user's machine
await validateDotnetInstalled(context);
const projectPath = nonNullProp(context, 'logicAppFolderPath');
const isDotNetInstalled = await validateDotNetIsInstalled(context, projectPath);
if (!isDotNetInstalled) {
return;
}
return new CodelessFunctionWorkflow();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ import type { MessageItem } from 'vscode';
/**
* Checks if dotnet 6 is installed, and installs it if needed.
* @param {IActionContext} context - Workflow file path.
* @param {string} message - Message for warning.
* @param {string} fsPath - Workspace file system path.
* @returns {Promise<boolean>} Returns true if it is installed or was sucessfully installed, otherwise returns false.
*/
export async function validateDotNetIsInstalled(context: IActionContext, message: string, fsPath: string): Promise<boolean> {
export async function validateDotNetIsInstalled(context: IActionContext, fsPath: string): Promise<boolean> {
let input: MessageItem | undefined;
let installed = false;
const install: MessageItem = { title: localize('install', 'Install') };

const message: string = localize('installDotnetSDK', 'You must have the .NET SDK installed. Would you like to install it now?');
await callWithTelemetryAndErrorHandling('azureLogicAppsStandard.validateDotNetIsInstalled', async (innerContext: IActionContext) => {
innerContext.errorHandling.suppressDisplay = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
addLibToPublishPath,
} from '../../utils/codeless/updateBuildFile';
import { getLocalDotNetVersionFromBinaries, getProjFiles, getTemplateKeyFromProjFile } from '../../utils/dotnet/dotnet';
import { validateDotnetInstalled, getFramework, executeDotnetTemplateCommand } from '../../utils/dotnet/executeDotnetTemplateCommand';
import { getFramework, executeDotnetTemplateCommand } from '../../utils/dotnet/executeDotnetTemplateCommand';
import { wrapArgInQuotes } from '../../utils/funcCoreTools/cpUtils';
import { tryGetMajorVersion, tryParseFuncVersion } from '../../utils/funcCoreTools/funcVersion';
import { getWorkspaceSetting } from '../../utils/vsCodeConfig/settings';
Expand All @@ -38,9 +38,13 @@ import { ProjectLanguage } from '@microsoft/vscode-extension-logic-apps';
import * as fse from 'fs-extra';
import * as path from 'path';
import * as vscode from 'vscode';
import { validateDotNetIsInstalled } from '../dotnet/validateDotNetInstalled';

export async function switchToDotnetProject(context: IProjectWizardContext, target: vscode.Uri) {
await validateDotnetInstalled(context);
const isDotNetInstalled = await validateDotNetIsInstalled(context, target.fsPath);
if (!isDotNetInstalled) {
return;
}

if (target === undefined) {
const workspaceFolders = vscode.workspace.workspaceFolders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { validateDotNetIsInstalled } from '../../commands/dotnet/validateDotNetInstalled';
import { getLatestVersion, getRelease } from '../../utils/cliFeed';
import { getTemplateKeyFromFeedEntry, getTemplateKeyFromProjFile } from '../../utils/dotnet/dotnet';
import {
validateDotnetInstalled,
executeDotnetTemplateCommand,
getDotnetItemTemplatePath,
getDotnetProjectTemplatePath,
Expand Down Expand Up @@ -53,8 +53,6 @@ export class DotnetTemplateProvider extends TemplateProviderBase {
}

public async getLatestTemplates(context: IActionContext, latestTemplateVersion: string): Promise<ITemplates> {
await validateDotnetInstalled(context);

const projKey = await this.getProjKey(context);
const projectFilePath: string = getDotnetProjectTemplatePath(this.version, projKey);
const itemFilePath: string = getDotnetItemTemplatePath(this.version, projKey);
Expand Down
Loading