diff --git a/Tasks/VsTestV2/task.json b/Tasks/VsTestV2/task.json index 2e8b3a6eaf26..56b21b6d0dc4 100644 --- a/Tasks/VsTestV2/task.json +++ b/Tasks/VsTestV2/task.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 2, - "Minor": 261, + "Minor": 266, "Patch": 0 }, "demands": [ diff --git a/Tasks/VsTestV2/task.loc.json b/Tasks/VsTestV2/task.loc.json index 06b8de2e70e3..5bb9a38d1b39 100644 --- a/Tasks/VsTestV2/task.loc.json +++ b/Tasks/VsTestV2/task.loc.json @@ -17,7 +17,7 @@ "author": "Microsoft Corporation", "version": { "Major": 2, - "Minor": 261, + "Minor": 266, "Patch": 0 }, "demands": [ diff --git a/Tasks/VsTestV2/versionfinder.ts b/Tasks/VsTestV2/versionfinder.ts index 6a6b14b1c385..153c0b4105f1 100644 --- a/Tasks/VsTestV2/versionfinder.ts +++ b/Tasks/VsTestV2/versionfinder.ts @@ -17,11 +17,11 @@ 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')); @@ -29,14 +29,10 @@ export function getVsTestRunnerDetails(testConfig: models.TestConfigurations) { } 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)); } @@ -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) { diff --git a/Tasks/VsTestV3/task.json b/Tasks/VsTestV3/task.json index 966b20b8ef7c..0020cc70029d 100644 --- a/Tasks/VsTestV3/task.json +++ b/Tasks/VsTestV3/task.json @@ -18,7 +18,7 @@ "version": { "Major": 3, "Minor": 266, - "Patch": 0 + "Patch": 1 }, "demands": [ "vstest" diff --git a/Tasks/VsTestV3/task.loc.json b/Tasks/VsTestV3/task.loc.json index 9cbed9c3c3fd..3be5c48194b3 100644 --- a/Tasks/VsTestV3/task.loc.json +++ b/Tasks/VsTestV3/task.loc.json @@ -18,7 +18,7 @@ "version": { "Major": 3, "Minor": 266, - "Patch": 0 + "Patch": 1 }, "demands": [ "vstest" diff --git a/Tasks/VsTestV3/versionfinder.ts b/Tasks/VsTestV3/versionfinder.ts index 6a6b14b1c385..153c0b4105f1 100644 --- a/Tasks/VsTestV3/versionfinder.ts +++ b/Tasks/VsTestV3/versionfinder.ts @@ -17,11 +17,11 @@ 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')); @@ -29,14 +29,10 @@ export function getVsTestRunnerDetails(testConfig: models.TestConfigurations) { } 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)); } @@ -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) {