From 3ae9f52628237e61b47b930af61865f77e6a7c16 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 31 Mar 2025 09:24:50 +0200 Subject: [PATCH 1/5] Add support for Microsoft.Testing.Platform in DotNetCoreCLIV2 --- Tasks/DotNetCoreCLIV2/dotnetcore.ts | 30 ++++++++++++++++++++++++++++- Tasks/DotNetCoreCLIV2/task.json | 4 ++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Tasks/DotNetCoreCLIV2/dotnetcore.ts b/Tasks/DotNetCoreCLIV2/dotnetcore.ts index ac2a8caa157b..d1f360772138 100644 --- a/Tasks/DotNetCoreCLIV2/dotnetcore.ts +++ b/Tasks/DotNetCoreCLIV2/dotnetcore.ts @@ -3,6 +3,7 @@ import tr = require("azure-pipelines-task-lib/toolrunner"); import path = require("path"); import fs = require("fs"); import ltx = require("ltx"); +import * as toml from 'toml'; var archiver = require('archiver'); var uuidV4 = require('uuid/v4'); const nodeVersion = parseInt(process.version.split('.')[0].replace('v', '')); @@ -145,13 +146,27 @@ export class dotNetExe { } } + private getIsMicrosoftTestingPlatform(): boolean { + if (!tl.exists("dotnet.config")) { + return false; + } + + let dotnetConfig = fs.readFileSync("dotnet.config", 'utf8'); + return toml.parse(dotnetConfig).dotnet?.test?.runner?.name === 'Microsoft.Testing.Platform'; + } + private async executeTestCommand(): Promise { const dotnetPath = tl.which('dotnet', true); console.log(tl.loc('DeprecatedDotnet2_2_And_3_0')); const enablePublishTestResults: boolean = tl.getBoolInput('publishTestResults', false) || false; const resultsDirectory = tl.getVariable('Agent.TempDirectory'); if (enablePublishTestResults && enablePublishTestResults === true) { - this.arguments = ` --logger trx --results-directory "${resultsDirectory}" `.concat(this.arguments); + const isMTP: boolean = this.getIsMicrosoftTestingPlatform(); + if (isMTP) { + this.arguments = ` --report-trx --results-directory "${resultsDirectory}" `.concat(this.arguments); + } else { + this.arguments = ` --logger trx --results-directory "${resultsDirectory}" `.concat(this.arguments); + } } // Remove old trx files @@ -171,6 +186,19 @@ export class dotNetExe { const projectFile = projectFiles[fileIndex]; const dotnet = tl.tool(dotnetPath); dotnet.arg(this.command); + // https://github.com/dotnet/sdk/blob/cbb8f75623c4357919418d34c53218ca9b57358c/src/Cli/dotnet/Commands/Test/CliConstants.cs#L34 + if (projectFile.endsWith(".proj") || projectFile.EndsWith(".csproj") || projectFile.EndsWith(".vbproj") || projectFile.EndsWith(".fsproj")) { + dotnet.arg("--project"); + } + else if (projectFile.endsWith(".sln") || projectFile.endsWith(".slnx") || projectFile.endsWith(".slnf")) { + dotnet.arg("--solution"); + } + else { + tl.error(`Project file '${projectFile}' has an unrecognized extension.`); + failedProjects.push(projectFile); + continue; + } + dotnet.arg(projectFile); dotnet.line(this.arguments); try { diff --git a/Tasks/DotNetCoreCLIV2/task.json b/Tasks/DotNetCoreCLIV2/task.json index a6b67add61d8..2622f178baec 100644 --- a/Tasks/DotNetCoreCLIV2/task.json +++ b/Tasks/DotNetCoreCLIV2/task.json @@ -17,8 +17,8 @@ "demands": [], "version": { "Major": 2, - "Minor": 247, - "Patch": 3 + "Minor": 255, + "Patch": 0 }, "minimumAgentVersion": "2.144.0", "instanceNameFormat": "dotnet $(command)", From ac72989d223a5194e65e01700d0181ab8f2be68d Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 2 Apr 2025 09:58:39 +0200 Subject: [PATCH 2/5] Fix --- Tasks/DotNetCoreCLIV2/dotnetcore.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Tasks/DotNetCoreCLIV2/dotnetcore.ts b/Tasks/DotNetCoreCLIV2/dotnetcore.ts index d1f360772138..1ea7863ba4c8 100644 --- a/Tasks/DotNetCoreCLIV2/dotnetcore.ts +++ b/Tasks/DotNetCoreCLIV2/dotnetcore.ts @@ -160,8 +160,9 @@ export class dotNetExe { console.log(tl.loc('DeprecatedDotnet2_2_And_3_0')); const enablePublishTestResults: boolean = tl.getBoolInput('publishTestResults', false) || false; const resultsDirectory = tl.getVariable('Agent.TempDirectory'); + const isMTP: boolean = this.getIsMicrosoftTestingPlatform(); + if (enablePublishTestResults && enablePublishTestResults === true) { - const isMTP: boolean = this.getIsMicrosoftTestingPlatform(); if (isMTP) { this.arguments = ` --report-trx --results-directory "${resultsDirectory}" `.concat(this.arguments); } else { @@ -186,17 +187,20 @@ export class dotNetExe { const projectFile = projectFiles[fileIndex]; const dotnet = tl.tool(dotnetPath); dotnet.arg(this.command); - // https://github.com/dotnet/sdk/blob/cbb8f75623c4357919418d34c53218ca9b57358c/src/Cli/dotnet/Commands/Test/CliConstants.cs#L34 - if (projectFile.endsWith(".proj") || projectFile.EndsWith(".csproj") || projectFile.EndsWith(".vbproj") || projectFile.EndsWith(".fsproj")) { - dotnet.arg("--project"); - } - else if (projectFile.endsWith(".sln") || projectFile.endsWith(".slnx") || projectFile.endsWith(".slnf")) { - dotnet.arg("--solution"); - } - else { - tl.error(`Project file '${projectFile}' has an unrecognized extension.`); - failedProjects.push(projectFile); - continue; + + if (isMTP) { + // https://github.com/dotnet/sdk/blob/cbb8f75623c4357919418d34c53218ca9b57358c/src/Cli/dotnet/Commands/Test/CliConstants.cs#L34 + if (projectFile.endsWith(".proj") || projectFile.EndsWith(".csproj") || projectFile.EndsWith(".vbproj") || projectFile.EndsWith(".fsproj")) { + dotnet.arg("--project"); + } + else if (projectFile.endsWith(".sln") || projectFile.endsWith(".slnx") || projectFile.endsWith(".slnf")) { + dotnet.arg("--solution"); + } + else { + tl.error(`Project file '${projectFile}' has an unrecognized extension.`); + failedProjects.push(projectFile); + continue; + } } dotnet.arg(projectFile); From 4c8b7d09e579104dd1a360761bb8fef8316dbeb4 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Fri, 4 Apr 2025 09:52:41 +0200 Subject: [PATCH 3/5] Fix build errors --- Tasks/DotNetCoreCLIV2/dotnetcore.ts | 2 +- Tasks/DotNetCoreCLIV2/package-lock.json | 7 +++++++ Tasks/DotNetCoreCLIV2/package.json | 1 + Tasks/DotNetCoreCLIV2/task.loc.json | 4 ++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Tasks/DotNetCoreCLIV2/dotnetcore.ts b/Tasks/DotNetCoreCLIV2/dotnetcore.ts index 1ea7863ba4c8..dba9dffdf1ce 100644 --- a/Tasks/DotNetCoreCLIV2/dotnetcore.ts +++ b/Tasks/DotNetCoreCLIV2/dotnetcore.ts @@ -147,7 +147,7 @@ export class dotNetExe { } private getIsMicrosoftTestingPlatform(): boolean { - if (!tl.exists("dotnet.config")) { + if (!tl.exist("dotnet.config")) { return false; } diff --git a/Tasks/DotNetCoreCLIV2/package-lock.json b/Tasks/DotNetCoreCLIV2/package-lock.json index 83ca498b9781..d7234645f9f9 100644 --- a/Tasks/DotNetCoreCLIV2/package-lock.json +++ b/Tasks/DotNetCoreCLIV2/package-lock.json @@ -16,6 +16,7 @@ "azure-pipelines-task-lib": "4.16.0", "azure-pipelines-tasks-packaging-common": "3.246.2", "azure-pipelines-tasks-utility-common": "3.246.0", + "toml": "^3.0.0", "uuid": "3.2.1" }, "devDependencies": { @@ -1706,6 +1707,12 @@ "node": ">=8.0" } }, + "node_modules/toml": { + "version": "3.0.0", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/toml/-/toml-3.0.0.tgz", + "integrity": "sha1-NCFg8a8ZBOydIE0DpdYSItdixe4=", + "license": "MIT" + }, "node_modules/truncate-utf8-bytes": { "version": "1.0.2", "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", diff --git a/Tasks/DotNetCoreCLIV2/package.json b/Tasks/DotNetCoreCLIV2/package.json index 29daadf0b7cc..df6b5e0a1ffe 100644 --- a/Tasks/DotNetCoreCLIV2/package.json +++ b/Tasks/DotNetCoreCLIV2/package.json @@ -24,6 +24,7 @@ "azure-pipelines-task-lib": "4.16.0", "azure-pipelines-tasks-packaging-common": "3.246.2", "azure-pipelines-tasks-utility-common": "3.246.0", + "toml": "^3.0.0", "uuid": "3.2.1" }, "devDependencies": { diff --git a/Tasks/DotNetCoreCLIV2/task.loc.json b/Tasks/DotNetCoreCLIV2/task.loc.json index b6d377182224..b6bf3860df77 100644 --- a/Tasks/DotNetCoreCLIV2/task.loc.json +++ b/Tasks/DotNetCoreCLIV2/task.loc.json @@ -17,8 +17,8 @@ "demands": [], "version": { "Major": 2, - "Minor": 247, - "Patch": 3 + "Minor": 255, + "Patch": 0 }, "minimumAgentVersion": "2.144.0", "instanceNameFormat": "ms-resource:loc.instanceNameFormat", From fd4872aca17e3a3e8634a7531536d4079a47df2a Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Fri, 4 Apr 2025 11:59:47 +0200 Subject: [PATCH 4/5] Fix --- Tasks/DotNetCoreCLIV2/dotnetcore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/DotNetCoreCLIV2/dotnetcore.ts b/Tasks/DotNetCoreCLIV2/dotnetcore.ts index dba9dffdf1ce..804944aec1bb 100644 --- a/Tasks/DotNetCoreCLIV2/dotnetcore.ts +++ b/Tasks/DotNetCoreCLIV2/dotnetcore.ts @@ -190,7 +190,7 @@ export class dotNetExe { if (isMTP) { // https://github.com/dotnet/sdk/blob/cbb8f75623c4357919418d34c53218ca9b57358c/src/Cli/dotnet/Commands/Test/CliConstants.cs#L34 - if (projectFile.endsWith(".proj") || projectFile.EndsWith(".csproj") || projectFile.EndsWith(".vbproj") || projectFile.EndsWith(".fsproj")) { + if (projectFile.endsWith(".proj") || projectFile.endsWith(".csproj") || projectFile.endsWith(".vbproj") || projectFile.endsWith(".fsproj")) { dotnet.arg("--project"); } else if (projectFile.endsWith(".sln") || projectFile.endsWith(".slnx") || projectFile.endsWith(".slnf")) { From 29f95748794b8402bded154296749e5eedc27168 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 14 Apr 2025 09:32:56 +0200 Subject: [PATCH 5/5] Add opt-out mechanism from dotnet.config --- Tasks/DotNetCoreCLIV2/dotnetcore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/DotNetCoreCLIV2/dotnetcore.ts b/Tasks/DotNetCoreCLIV2/dotnetcore.ts index 804944aec1bb..4cc5aa783429 100644 --- a/Tasks/DotNetCoreCLIV2/dotnetcore.ts +++ b/Tasks/DotNetCoreCLIV2/dotnetcore.ts @@ -160,7 +160,7 @@ export class dotNetExe { console.log(tl.loc('DeprecatedDotnet2_2_And_3_0')); const enablePublishTestResults: boolean = tl.getBoolInput('publishTestResults', false) || false; const resultsDirectory = tl.getVariable('Agent.TempDirectory'); - const isMTP: boolean = this.getIsMicrosoftTestingPlatform(); + const isMTP: boolean = !tl.getPipelineFeature('DisableDotnetConfigDetection') && this.getIsMicrosoftTestingPlatform(); if (enablePublishTestResults && enablePublishTestResults === true) { if (isMTP) {