Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Tasks/VsTestV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 261,
"Minor": 266,
"Patch": 0
},
"demands": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/VsTestV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 261,
"Minor": 266,
"Patch": 0
},
"demands": [
Expand Down
26 changes: 11 additions & 15 deletions Tasks/VsTestV2/versionfinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,22 @@ export function getVsTestRunnerDetails(testConfig: models.TestConfigurations) {
return;
}

const vstestLocationEscaped = vstestexeLocation.replace(/\\/g, '\\\\');
const wmicTool = tl.tool('wmic');
const wmicArgs = ['datafile', 'where', 'name=\''.concat(vstestLocationEscaped, '\''), 'get', 'Version', '/Value'];
wmicTool.arg(wmicArgs);
let output = wmicTool.execSync({ silent: true } as tr.IExecSyncOptions).stdout;
// Use PowerShell Get-ItemProperty instead of deprecated wmic
const powershellTool = tl.tool('powershell');
const powershellArgs = ['-Command', `try { (Get-ItemProperty -Path '${vstestexeLocation}' -ErrorAction Stop).VersionInfo.FileVersion } catch { throw "Failed to get version info for ${vstestexeLocation}: $_" }`];
powershellTool.arg(powershellArgs);
let output = powershellTool.execSync({ silent: true } as tr.IExecSyncOptions).stdout;

if (utils.Helper.isNullOrWhitespace(output)) {
tl.error(tl.loc('ErrorReadingVstestVersion'));
throw new Error(tl.loc('ErrorReadingVstestVersion'));
}
output = output.trim();
tl.debug('VSTest Version information: ' + output);
const verSplitArray = output.split('=');
if (verSplitArray.length !== 2) {
tl.error(tl.loc('ErrorReadingVstestVersion'));
throw new Error(tl.loc('ErrorReadingVstestVersion'));
}

const versionArray = verSplitArray[1].split('.');
if (versionArray.length !== 4) {

// PowerShell returns version directly, no need to split by '='
const versionArray = output.split('.');
if (versionArray.length < 3) {
tl.warning(tl.loc('UnexpectedVersionString', output));
throw new Error(tl.loc('UnexpectedVersionString', output));
}
Expand All @@ -48,8 +44,8 @@ export function getVsTestRunnerDetails(testConfig: models.TestConfigurations) {
ci.publishEvent({ testplatform: `${majorVersion}.${minorVersion}.${patchNumber}` });

if (isNaN(majorVersion) || isNaN(minorVersion) || isNaN(patchNumber)) {
tl.warning(tl.loc('UnexpectedVersionNumber', verSplitArray[1]));
throw new Error(tl.loc('UnexpectedVersionNumber', verSplitArray[1]));
tl.warning(tl.loc('UnexpectedVersionNumber', output));
throw new Error(tl.loc('UnexpectedVersionNumber', output));
}

switch (majorVersion) {
Expand Down
2 changes: 1 addition & 1 deletion Tasks/VsTestV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 3,
"Minor": 266,
"Patch": 0
"Patch": 1
},
"demands": [
"vstest"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/VsTestV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 3,
"Minor": 266,
"Patch": 0
"Patch": 1
},
"demands": [
"vstest"
Expand Down
26 changes: 11 additions & 15 deletions Tasks/VsTestV3/versionfinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,22 @@ export function getVsTestRunnerDetails(testConfig: models.TestConfigurations) {
return;
}

const vstestLocationEscaped = vstestexeLocation.replace(/\\/g, '\\\\');
const wmicTool = tl.tool('wmic');
const wmicArgs = ['datafile', 'where', 'name=\''.concat(vstestLocationEscaped, '\''), 'get', 'Version', '/Value'];
wmicTool.arg(wmicArgs);
let output = wmicTool.execSync({ silent: true } as tr.IExecSyncOptions).stdout;
// Use PowerShell Get-ItemProperty instead of deprecated wmic
const powershellTool = tl.tool('powershell');
const powershellArgs = ['-Command', `try { (Get-ItemProperty -Path '${vstestexeLocation}' -ErrorAction Stop).VersionInfo.FileVersion } catch { throw "Failed to get version info for ${vstestexeLocation}: $_" }`];
powershellTool.arg(powershellArgs);
let output = powershellTool.execSync({ silent: true } as tr.IExecSyncOptions).stdout;

if (utils.Helper.isNullOrWhitespace(output)) {
tl.error(tl.loc('ErrorReadingVstestVersion'));
throw new Error(tl.loc('ErrorReadingVstestVersion'));
}
output = output.trim();
tl.debug('VSTest Version information: ' + output);
const verSplitArray = output.split('=');
if (verSplitArray.length !== 2) {
tl.error(tl.loc('ErrorReadingVstestVersion'));
throw new Error(tl.loc('ErrorReadingVstestVersion'));
}

const versionArray = verSplitArray[1].split('.');
if (versionArray.length !== 4) {

// PowerShell returns version directly, no need to split by '='

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment might be more confusing than helpful when change has been committed.

const versionArray = output.split('.');
if (versionArray.length < 3) {
tl.warning(tl.loc('UnexpectedVersionString', output));
throw new Error(tl.loc('UnexpectedVersionString', output));
}
Expand All @@ -48,8 +44,8 @@ export function getVsTestRunnerDetails(testConfig: models.TestConfigurations) {
ci.publishEvent({ testplatform: `${majorVersion}.${minorVersion}.${patchNumber}` });

if (isNaN(majorVersion) || isNaN(minorVersion) || isNaN(patchNumber)) {
tl.warning(tl.loc('UnexpectedVersionNumber', verSplitArray[1]));
throw new Error(tl.loc('UnexpectedVersionNumber', verSplitArray[1]));
tl.warning(tl.loc('UnexpectedVersionNumber', output));
throw new Error(tl.loc('UnexpectedVersionNumber', output));
}

switch (majorVersion) {
Expand Down