Skip to content

Commit de07136

Browse files
authored
Skip CHCP Calls and Utilize DOTNET_CLI_UI_LANGUAGE (#2233)
* Set DOTNET_CLI_UI_LANGUAGE instead of chcp Calling chcp has significant performance impacts. One problem is if the dotnet host does not respect the language setting and a user only has the host or runtime installed. We cannot perform the architecture check in this case. Also adds NOLOGO to prevent the issue of first run exp + performance delay from it. * Consider when the output architecture is empty
1 parent 92ce511 commit de07136

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

vscode-dotnet-runtime-library/src/Acquisition/DotnetConditionValidator.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ Please set the PATH to a dotnet host that matches the architecture ${requirement
118118
return [];
119119
}
120120

121-
const findSDKsCommand = await this.setCodePage() ? CommandExecutor.makeCommand(`chcp`, [`65001`, `|`, `"${existingPath}"`, '--list-sdks']) :
122-
CommandExecutor.makeCommand(`"${existingPath}"`, ['--list-sdks']);
121+
const findSDKsCommand = CommandExecutor.makeCommand(`"${existingPath}"`, ['--list-sdks']);
123122

124123
const sdkInfo = await (this.executor!).execute(findSDKsCommand, { dotnetInstallToolCacheTtlMs: DOTNET_INFORMATION_CACHE_DURATION_MS }, false).then((result) =>
125124
{
@@ -144,13 +143,6 @@ Please set the PATH to a dotnet host that matches the architecture ${requirement
144143
return sdkInfo;
145144
}
146145

147-
private async setCodePage(): Promise<boolean>
148-
{
149-
// For Windows, we need to change the code page to UTF-8 to handle the output of the command. https://github.com/nodejs/node-v0.x-archive/issues/2190
150-
// Only certain builds of windows support UTF 8 so we need to check that we can use it.
151-
return os.platform() === 'win32' ? (await this.executor!.tryFindWorkingCommand([CommandExecutor.makeCommand('chcp', ['65001'])], { dotnetInstallToolCacheTtlMs: SYS_CMD_SEARCH_CACHE_DURATION_MS })) !== null : false;
152-
}
153-
154146
public stringVersionMeetsRequirement(availableVersion: string, requestedVersion: string, requirement: IDotnetFindPathContext): boolean
155147
{
156148
const availableMajor = Number(versionUtils.getMajor(availableVersion, this.workerContext.eventStream, this.workerContext));
@@ -256,7 +248,7 @@ Please set the PATH to a dotnet host that matches the architecture ${requirement
256248

257249
private stringArchitectureMeetsRequirement(outputArchitecture: string, requiredArchitecture: string | null | undefined): boolean
258250
{
259-
return !requiredArchitecture || outputArchitecture === '' || FileUtilities.dotnetInfoArchToNodeArch(outputArchitecture, this.workerContext.eventStream) === requiredArchitecture;
251+
return !requiredArchitecture || !outputArchitecture || FileUtilities.dotnetInfoArchToNodeArch(outputArchitecture, this.workerContext.eventStream) === requiredArchitecture;
260252
}
261253

262254
private allowPreview(availableVersion: string, requirement: IDotnetFindPathContext): boolean
@@ -275,8 +267,7 @@ Please set the PATH to a dotnet host that matches the architecture ${requirement
275267
return [];
276268
}
277269

278-
const findRuntimesCommand = await this.setCodePage() ? CommandExecutor.makeCommand(`chcp`, [`65001`, `|`, `"${existingPath}"`, '--list-runtimes']) :
279-
CommandExecutor.makeCommand(`"${existingPath}"`, ['--list-runtimes']);
270+
const findRuntimesCommand = CommandExecutor.makeCommand(`"${existingPath}"`, ['--list-runtimes']);
280271

281272
const windowsDesktopString = 'Microsoft.WindowsDesktop.App';
282273
const aspnetCoreString = 'Microsoft.AspNetCore.App';

vscode-dotnet-runtime-library/src/Utils/CommandExecutor.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,20 @@ ${stderr}`));
443443

444444
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
445445
options.encoding = 'utf8';
446+
447+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
448+
options.env ??= { ...process.env };
449+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
450+
options.env.DOTNET_CLI_UI_LANGUAGE ??= 'en-US';
451+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
452+
options.env.DOTNET_NOLOGO ??= 'true';
446453
}
447454
else
448455
{
449-
options = { cwd: path.resolve(__dirname), shell: true, encoding: 'utf8' };
456+
options = {
457+
cwd: path.resolve(__dirname), shell: true, encoding: 'utf8', env:
458+
{ ...process.env, DOTNET_CLI_UI_LANGUAGE: 'en-US', DOTNET_NOLOGO: 'true' }
459+
};
450460
}
451461

452462
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access

0 commit comments

Comments
 (0)