From b0f70a24da4d94a334398288b28ef9a10499876e Mon Sep 17 00:00:00 2001 From: Alex Weininger Date: Wed, 1 Mar 2023 12:29:51 -0800 Subject: [PATCH 1/2] Fix getting package references from csproj from multiple item groups --- src/utils/dotnetUtils.ts | 27 +++++++++++++++++++++++++++ src/utils/durableUtils.ts | 10 +++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/utils/dotnetUtils.ts b/src/utils/dotnetUtils.ts index c214cb3ef..3c1bf8cd6 100644 --- a/src/utils/dotnetUtils.ts +++ b/src/utils/dotnetUtils.ts @@ -128,4 +128,31 @@ export namespace dotnetUtils { } return result; } + + interface CSProjXml { + Project?: { + ItemGroup?: { + PackageReference?: { + '$': CSProjPackageReference; + }[]; + }[]; + } + } + + type CSProjPackageReference = { + Include: string; + } + + export function getPackageReferences(xml: CSProjXml): CSProjPackageReference[] { + const packageReferences: CSProjPackageReference[] = []; + xml.Project?.ItemGroup?.forEach((itemGroup) => { + const references = itemGroup.PackageReference; + if (references) { + references.forEach((reference) => { + packageReferences.push(reference.$); + }); + } + }); + return packageReferences; + } } diff --git a/src/utils/durableUtils.ts b/src/utils/durableUtils.ts index 361a8bd1d..9f53758e8 100644 --- a/src/utils/durableUtils.ts +++ b/src/utils/durableUtils.ts @@ -13,6 +13,7 @@ import { ext } from "../extensionVariables"; import { IHostJsonV2, INetheriteTaskJson, ISqlTaskJson, IStorageTaskJson } from "../funcConfig/host"; import { localize } from "../localize"; import { cpUtils } from "./cpUtils"; +import { dotnetUtils } from "./dotnetUtils"; import { hasNodeJsDependency } from "./nodeJsUtils"; import { pythonUtils } from "./pythonUtils"; import { venvUtils } from "./venvUtils"; @@ -107,14 +108,9 @@ export namespace durableUtils { const csProjContents: string = await AzExtFsExtra.readFile(csProjPaths[0].path); return new Promise((resolve) => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - xml2js.parseString(csProjContents, { explicitArray: false }, (err: any, result: any): void => { + xml2js.parseString(csProjContents, (err: Error, result: unknown): void => { if (result && !err) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access - let packageReferences = result?.['Project']?.['ItemGroup']?.[0]?.PackageReference ?? []; - packageReferences = (packageReferences instanceof Array) ? packageReferences : [packageReferences]; - // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access - resolve(packageReferences.some(p => /Durable/i.test(p?.['$']?.['Include'] ?? ''))); + resolve(dotnetUtils.getPackageReferences(result).some(p => /Durable/i.test(p.Include))); } }); }); From 1b1794a664044138ea73079489e537417d4b9d46 Mon Sep 17 00:00:00 2001 From: Alex Weininger Date: Wed, 1 Mar 2023 12:30:11 -0800 Subject: [PATCH 2/2] Add comment --- src/utils/dotnetUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/dotnetUtils.ts b/src/utils/dotnetUtils.ts index 3c1bf8cd6..7ecfd6492 100644 --- a/src/utils/dotnetUtils.ts +++ b/src/utils/dotnetUtils.ts @@ -145,6 +145,7 @@ export namespace dotnetUtils { export function getPackageReferences(xml: CSProjXml): CSProjPackageReference[] { const packageReferences: CSProjPackageReference[] = []; + // package references can be split across multiple item groups xml.Project?.ItemGroup?.forEach((itemGroup) => { const references = itemGroup.PackageReference; if (references) {