import { AzureWizardPromptStep , IAzureQuickPickItem } from "vscode-azureextensionui" ; import { hiddenStacksSetting } from "../../../constants" ; import { promptForFuncVersion } from "../../../FuncVersion" ; import { localize } from "../../../localize" ; import { cliFeedUtils } from "../../../utils/cliFeedUtils" ; import { dotnetUtils } from "../../../utils/dotnetUtils" ; import { getWorkspaceSetting } from "../../../vsCodeConfig/settings" ; import { IProjectWizardContext } from "../IProjectWizardContext" ; export class DotnetRuntimeStep extends AzureWizardPromptStep < IProjectWizardContext > { public static async createStep ( context ) { if ( context . targetFramework ) { context . targetFramework = typeof context . targetFramework === 'string' ? [ context . targetFramework ] : context . targetFramework ; const runtimes = await getRuntimes ( context ) ; const workerRuntime = runtimes . find ( runtime => context . targetFramework ?. includes ( runtime . targetFramework ) ) ; if ( ! workerRuntime ) { throw new Error ( localize ( 'unknownFramework' , 'Unrecognized target frameworks: "{0}". Available frameworks: {1}.' , context . targetFramework . map ( tf => `"${ tf }"` ) . join ( ', ' ) , runtimes . map ( rt => `"${ rt . targetFramework }"` ) . join ( ', ' ) ) ) ; } setWorkerRuntime ( context , workerRuntime ) ; } return new DotnetRuntimeStep ( ) ; } public async prompt ( context ) { const placeHolder = localize ( 'selectWorkerRuntime' , 'Select a .NET runtime' ) ; let result ; while ( true ) { result = ( await context . ui . showQuickPick ( this . getPicks ( context ) , { placeHolder } ) ) . data ; if ( ! result ) { context . version = await promptForFuncVersion ( context ) ; } else { break ; } } setWorkerRuntime ( context , result ) ; } public shouldPrompt ( context ) { return ! context . workerRuntime ; } private async getPicks ( context ) { const runtimes = await getRuntimes ( context ) ; const picks = [ ] ; for ( const runtime of runtimes ) { picks . push ( { label : runtime . displayInfo . displayName , description : runtime . displayInfo . description , data : runtime } ) ; } picks . push ( { label : localize ( 'changeFuncVersion' , '$(gear) Change Azure Functions version' ) , description : localize ( 'currentFuncVersion' , 'Current: {0}' , context . version ) , data : undefined , suppressPersistence : true } ) ; return picks ; } } async function getRuntimes ( context ) { const funcRelease = await cliFeedUtils . getRelease ( context , await cliFeedUtils . getLatestVersion ( context , context . version ) ) ; const showHiddenStacks = getWorkspaceSetting < boolean > ( hiddenStacksSetting ) ; const runtimes = Object . values ( funcRelease . workerRuntimes . dotnet ) . filter ( r => ! r . displayInfo . hidden || showHiddenStacks ) ; if ( runtimes . length === 0 ) { throw new Error ( 'Internal error: No .NET worker runtimes found.' ) ; } return runtimes ; } function setWorkerRuntime ( context , runtime ) { context . workerRuntime = runtime ; context . projectTemplateKey = dotnetUtils . getTemplateKeyFromFeedEntry ( runtime ) ; }