Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
19 changes: 15 additions & 4 deletions src/commands/createNewProject/dotnetSteps/DotnetRuntimeStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ export class DotnetRuntimeStep extends AzureWizardPromptStep<IProjectWizardConte
public static async createStep(context: IProjectWizardContext): Promise<DotnetRuntimeStep> {
if (context.targetFramework) {
context.targetFramework = typeof context.targetFramework === 'string' ? [context.targetFramework] : context.targetFramework;
const runtimes = await getRuntimes(context);
const runtimes = (await getRuntimes(context))
Comment thread
alexweininger marked this conversation as resolved.
Outdated
// if a targetFramework was provided from createNewProject
const workerRuntime = runtimes.find(runtime => context.targetFramework?.includes(runtime.targetFramework));
const filteredRuntimes = runtimes.filter(runtime => context.targetFramework?.includes(runtime.targetFramework));
let workerRuntime: cliFeedUtils.IWorkerRuntime | undefined = undefined;
if (filteredRuntimes.length > 1) {
const placeHolder: string = localize('selectWorkerRuntime', 'Select a .NET runtime');
workerRuntime = (await context.ui.showQuickPick(new DotnetRuntimeStep().getPicks(context), { placeHolder })).data;
} else if (filteredRuntimes.length === 1) {
workerRuntime = filteredRuntimes[0];
}

if (!workerRuntime) {
throw new Error(localize('unknownFramework', 'Unrecognized target frameworks: "{0}". Available frameworks: {1}.',
context.targetFramework.map(tf => `"${tf}"`).join(', '),
Expand Down Expand Up @@ -49,8 +57,11 @@ export class DotnetRuntimeStep extends AzureWizardPromptStep<IProjectWizardConte
return !context.workerRuntime;
}

private async getPicks(context: IProjectWizardContext): Promise<IAzureQuickPickItem<cliFeedUtils.IWorkerRuntime | undefined>[]> {
const runtimes = await getRuntimes(context);
private async getPicks(context: IProjectWizardContext, runtimes?: cliFeedUtils.IWorkerRuntime[]): Promise<IAzureQuickPickItem<cliFeedUtils.IWorkerRuntime | undefined>[]> {
if (!runtimes) {
runtimes = await getRuntimes(context);
}

const picks: IAzureQuickPickItem<cliFeedUtils.IWorkerRuntime | undefined>[] = [];
for (const runtime of runtimes) {
picks.push({
Expand Down
28 changes: 25 additions & 3 deletions test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { runWithInputs } from '@microsoft/vscode-azext-dev';
import { type apiUtils } from "@microsoft/vscode-azext-utils";
import * as path from 'path';
import { extensions, type Extension } from "vscode";
import { ProjectLanguage, extensionId, nonNullValue, registerOnActionStartHandler } from '../extension.bundle';
import { FuncVersion, ProjectLanguage, extensionId, nonNullValue, registerOnActionStartHandler } from '../extension.bundle';
// eslint-disable-next-line no-restricted-imports
import { type AzureFunctionsExtensionApi } from '../src/vscode-azurefunctions.api';
import { getTestWorkspaceFolder, testFolderPath } from './global.test';
import { getJavaScriptValidateOptions, validateProject, type IValidateProjectOptions } from './project/validateProject';
import { getCSharpValidateOptions, getJavaScriptValidateOptions, validateProject, type IValidateProjectOptions } from './project/validateProject';

suite(`AzureFunctionsExtensionApi`, () => {
suite.only(`AzureFunctionsExtensionApi`, () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotta remove dis

let api: AzureFunctionsExtensionApi;

suiteSetup(() => {
Expand Down Expand Up @@ -73,4 +73,26 @@ suite(`AzureFunctionsExtensionApi`, () => {
);
await validateProject(folderPath, validateOptions);
});

test('createFunction dotnet with targetFramework', async () => {
const functionName: string = 'endpoint1';
const language: string = ProjectLanguage.CSharp;
const workspaceFolder = getTestWorkspaceFolder();
const projectSubpath = 'api';
const folderPath: string = path.join(workspaceFolder, projectSubpath);

await runWithInputs('api.createFunction', [language, /6/i, 'Company.Function', 'Anonymous'], registerOnActionStartHandler, async () => {
await api.createFunction({
folderPath,
functionName,
templateId: 'HttpTrigger',
languageFilter: /^C\#$/i,
functionSettings: { authLevel: 'anonymous' },
targetFramework: ['net8.0', 'net7.0', 'net6.0']
Comment thread
alexweininger marked this conversation as resolved.
});
});

const validateOptions: IValidateProjectOptions = getCSharpValidateOptions('net6.0', FuncVersion.v4);
await validateProject(folderPath, validateOptions);
});
});