Fix containerized project creation for .NET projects (#3988)

* Fix dotnet project creation

* Add comments

* Remove .NET 6.0 LTS from picks

* Add back .NET 6.0 LTS

* suggested changes
This commit is contained in:
Megan Mott 2024-02-28 13:12:29 -08:00 коммит произвёл GitHub
Родитель 0e26f73fbd
Коммит 353d3f54c2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 20 добавлений и 8 удалений

Просмотреть файл

@ -29,6 +29,8 @@ export interface IProjectWizardContext extends IActionContext {
openApiSpecificationFile?: Uri[];
targetFramework?: string | string[];
containerizedProject?: boolean;
}
export type OpenBehavior = 'AddToWorkspace' | 'OpenInNewWindow' | 'OpenInCurrentWindow' | 'AlreadyOpen' | 'DontOpen';

Просмотреть файл

@ -7,6 +7,7 @@ import { AzExtFsExtra, DialogResponses, type IActionContext } from '@microsoft/v
import * as path from 'path';
import { getMajorVersion, type FuncVersion } from '../../../FuncVersion';
import { ConnectionKey, ProjectLanguage, gitignoreFileName, hostFileName, localSettingsFileName } from '../../../constants';
import { ext } from '../../../extensionVariables';
import { MismatchBehavior, setLocalAppSetting } from '../../../funcConfig/local.settings';
import { localize } from "../../../localize";
import { executeDotnetTemplateCommand, validateDotnetInstalled } from '../../../templates/dotnet/executeDotnetTemplateCommand';
@ -31,10 +32,18 @@ export class DotnetProjectCreateStep extends ProjectCreateStepBase {
const projectName: string = path.basename(context.projectPath);
const projName: string = projectName + language === ProjectLanguage.FSharp ? '.fsproj' : '.csproj';
await this.confirmOverwriteExisting(context, projName);
const workerRuntime = nonNullProp(context, 'workerRuntime');
// For containerized function apps we need to call func init before intialization as we want the .csproj file to be overwritten with the correct version
// currentely the version created by func init is behind the template version
if (context.containerizedProject) {
const runtime = context.workerRuntime?.capabilities.includes('isolated') ? 'dotnet-isolated' : 'dotnet';
await cpUtils.executeCommand(ext.outputChannel, context.projectPath, "func", "init", "--worker-runtime", runtime, "--docker");
} else {
await this.confirmOverwriteExisting(context, projName);
}
const majorVersion: string = getMajorVersion(version);
const workerRuntime = nonNullProp(context, 'workerRuntime');
let identity: string = workerRuntime.projectTemplateId.csharp;
if (language === ProjectLanguage.FSharp) {
identity = identity.replace('CSharp', 'FSharp'); // they don't have FSharp in the feed yet

Просмотреть файл

@ -61,6 +61,7 @@ export async function createNewProjectInternal(context: IActionContext, options:
if (!await validateFuncCoreToolsInstalled(context, message)) {
throw new UserCancelledError('validateFuncCoreToolsInstalled');
}
wizardContext.containerizedProject = true;
}
if (options.folderPath) {

Просмотреть файл

@ -12,12 +12,11 @@ export class CreateDockerfileProjectStep extends AzureWizardExecuteStep<IFunctio
public priority: number = 100;
public async execute(context: IFunctionWizardContext): Promise<void> {
let language = nonNullValueAndProp(context, 'language').toLowerCase();
if (language === 'c#') {
language = 'csharp';
const language = nonNullValueAndProp(context, 'language').toLowerCase();
// If the language is C# this command needs to be called earlier as the versioning in the .csproj file is different from the one in the template
if (language !== 'c#') {
await cpUtils.executeCommand(ext.outputChannel, nonNullValueAndProp(context, 'projectPath'), "func", "init", "--worker-runtime", language, "--docker");
}
await cpUtils.executeCommand(ext.outputChannel, nonNullValueAndProp(context, 'projectPath'), "func", "init", "--worker-runtime", language, "--docker");
}
public shouldExecute(): boolean {

Просмотреть файл

@ -49,7 +49,8 @@ export namespace cliFeedUtils {
projectTemplates: string;
projectTemplateId: {
csharp: string;
}
},
capabilities: string;
}
export async function getLatestVersion(context: IActionContext, version: FuncVersion): Promise<string> {