Skip to content

Commit 74e085d

Browse files
tarunramsinghaniYoussef1313azure-pipelines-botrishabhmalikMS
authored
Adjust MTP detection (#21315)
* Adjust MTP detection * Update minor to 263 * Update minor to 263 * Handle errors reading global.json, just in case. Added error handling when parsing global.json for test runner. * updated task.loc.json --------- Co-authored-by: Youssef1313 <[email protected]> Co-authored-by: azure-pipelines-bot <[email protected]> Co-authored-by: rishabhmalikMS <[email protected]>
1 parent 638559e commit 74e085d

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

Tasks/DotNetCoreCLIV2/dotnetcore.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import tr = require("azure-pipelines-task-lib/toolrunner");
33
import path = require("path");
44
import fs = require("fs");
55
import ltx = require("ltx");
6-
import * as toml from 'toml';
6+
import * as JSON5 from 'json5';
77
var archiver = require('archiver');
88
var uuidV4 = require('uuid/v4');
99
const nodeVersion = parseInt(process.version.split('.')[0].replace('v', ''));
@@ -147,12 +147,24 @@ export class dotNetExe {
147147
}
148148

149149
private getIsMicrosoftTestingPlatform(): boolean {
150-
if (!tl.exist("dotnet.config")) {
150+
if (!tl.exist("global.json")) {
151+
tl.debug("global.json not found. Test run is VSTest");
151152
return false;
152153
}
153154

154-
let dotnetConfig = fs.readFileSync("dotnet.config", 'utf8');
155-
return toml.parse(dotnetConfig).dotnet?.test?.runner?.name === 'Microsoft.Testing.Platform';
155+
let globalJsonContents = fs.readFileSync("global.json", 'utf8');
156+
if (!globalJsonContents.length) {
157+
return false;
158+
}
159+
160+
try {
161+
const testRunner = JSON5.parse(globalJsonContents)?.test?.runner;
162+
tl.debug(`global.json is found. Test run is read as '${testRunner}'`);
163+
return testRunner === 'Microsoft.Testing.Platform';
164+
} catch (error) {
165+
tl.warning(`Error occurred reading global.json: ${error}`);
166+
return false;
167+
}
156168
}
157169

158170
private async executeTestCommand(): Promise<void> {

Tasks/DotNetCoreCLIV2/package-lock.json

Lines changed: 13 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tasks/DotNetCoreCLIV2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"azure-pipelines-task-lib": "4.16.0",
2727
"azure-pipelines-tasks-packaging-common": "3.246.2",
2828
"azure-pipelines-tasks-utility-common": "3.258.0",
29-
"toml": "^3.0.0",
29+
"json5": "^2.2.3",
3030
"uuid": "3.2.1"
3131
},
3232
"devDependencies": {

Tasks/DotNetCoreCLIV2/task.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"demands": [],
1818
"version": {
1919
"Major": 2,
20-
"Minor": 259,
20+
"Minor": 263,
2121
"Patch": 0
2222
},
2323
"minimumAgentVersion": "2.144.0",
@@ -604,4 +604,4 @@
604604
"Error_IncludeNuGetOrgEnabled": "Packages failed to restore. Edit your build task and set 'includeNuGetOrg' to 'false' or deselect 'Use packages from NuGet.org'.",
605605
"Warning_UnsupportedServiceConnectionAuth": "The service connection does not use a supported authentication method. Please use a service connection with personal access token based auth."
606606
}
607-
}
607+
}

Tasks/DotNetCoreCLIV2/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"demands": [],
1818
"version": {
1919
"Major": 2,
20-
"Minor": 259,
20+
"Minor": 263,
2121
"Patch": 0
2222
},
2323
"minimumAgentVersion": "2.144.0",

0 commit comments

Comments
 (0)