Skip to content

Add support for Microsoft.Testing.Platform in DotNetCoreCLIV2 #20960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all 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
34 changes: 33 additions & 1 deletion Tasks/DotNetCoreCLIV2/dotnetcore.ts
Original file line number Diff line number Diff line change
@@ -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,28 @@ export class dotNetExe {
}
}

private getIsMicrosoftTestingPlatform(): boolean {
if (!tl.exist("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<void> {
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');
const isMTP: boolean = !tl.getPipelineFeature('DisableDotnetConfigDetection') && this.getIsMicrosoftTestingPlatform();

if (enablePublishTestResults && enablePublishTestResults === true) {
this.arguments = ` --logger trx --results-directory "${resultsDirectory}" `.concat(this.arguments);
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 +187,22 @@ export class dotNetExe {
const projectFile = projectFiles[fileIndex];
const dotnet = tl.tool(dotnetPath);
dotnet.arg(this.command);

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);
dotnet.line(this.arguments);
try {
7 changes: 7 additions & 0 deletions Tasks/DotNetCoreCLIV2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Tasks/DotNetCoreCLIV2/package.json
Original file line number Diff line number Diff line change
@@ -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": {
4 changes: 2 additions & 2 deletions Tasks/DotNetCoreCLIV2/task.json
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@
"demands": [],
"version": {
"Major": 2,
"Minor": 247,
"Patch": 3
"Minor": 255,
"Patch": 0
},
"minimumAgentVersion": "2.144.0",
"instanceNameFormat": "dotnet $(command)",
4 changes: 2 additions & 2 deletions Tasks/DotNetCoreCLIV2/task.loc.json
Original file line number Diff line number Diff line change
@@ -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",