Skip to content

Commit 23186b5

Browse files
author
Katherine Reynolds
committed
Small enhancements for VS profile generation
1 parent ad14922 commit 23186b5

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/cascadia/TerminalSettingsModel/VsDevCmdGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ std::wstring VsDevCmdGenerator::GetProfileCommandLine(const VsSetupConfiguration
4545
// The "-startdir" parameter will prevent "vsdevcmd" from automatically
4646
// setting the shell path so the path in the profile will be used instead.
4747
#if defined(_M_ARM64)
48-
commandLine.append(LR"(" -startdir=none -arch=arm64 -host_arch=x64)");
48+
commandLine.append(LR"(" -startdir=none -arch=arm64 -host_arch=arm64)");
4949
#elif defined(_M_AMD64)
5050
commandLine.append(LR"(" -startdir=none -arch=x64 -host_arch=x64)");
5151
#else

src/cascadia/TerminalSettingsModel/VsDevShellGenerator.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
using namespace winrt::Microsoft::Terminal::Settings::Model;
1010

11-
void VsDevShellGenerator::GenerateProfiles(const VsSetupConfiguration::VsSetupInstance& instance, bool hidden, std::vector<winrt::com_ptr<implementation::Profile>>& profiles) const
11+
void VsDevShellGenerator::GenerateProfiles(
12+
const VsSetupConfiguration::VsSetupInstance& instance,
13+
bool hidden,
14+
std::vector<winrt::com_ptr<implementation::Profile>>& profiles) const
1215
{
1316
try
1417
{
@@ -39,17 +42,34 @@ std::wstring VsDevShellGenerator::GetProfileName(const VsSetupConfiguration::VsS
3942

4043
std::wstring VsDevShellGenerator::GetProfileCommandLine(const VsSetupConfiguration::VsSetupInstance& instance) const
4144
{
42-
// The triple-quotes are a PowerShell path escape sequence that can safely be stored in a JSON object.
43-
// The "SkipAutomaticLocation" parameter will prevent "Enter-VsDevShell" from automatically setting the shell path
44-
// so the path in the profile will be used instead.
45+
// Build this in stages, so reserve space now
4546
std::wstring commandLine;
4647
commandLine.reserve(256);
47-
commandLine.append(LR"(powershell.exe -NoExit -Command "&{Import-Module """)");
48+
49+
// Try to detect if `pwsh.exe` is available in the PATH, if so we want to use that
50+
// Allow some extra space in case user put it somewhere odd
51+
// We do need to allocate space for the full path even if we don't want to paste the whole thing in
52+
wchar_t pwshPath[MAX_PATH] = { 0 };
53+
const auto pwshExeName = L"pwsh.exe";
54+
if (SearchPathW(nullptr, pwshExeName, nullptr, MAX_PATH, pwshPath, nullptr))
55+
{
56+
commandLine.append(pwshExeName);
57+
}
58+
else
59+
{
60+
commandLine.append(L"powershell.exe");
61+
}
62+
63+
64+
// The triple-quotes are a PowerShell path escape sequence that can safely be stored in a JSON object.
65+
// The "SkipAutomaticLocation" parameter will prevent "Enter-VsDevShell" from automatically setting the shell path
66+
// so the path in the profile will be used instead
67+
commandLine.append(LR"( -NoExit -Command "&{Import-Module """)");
4868
commandLine.append(GetDevShellModulePath(instance));
4969
commandLine.append(LR"("""; Enter-VsDevShell )");
5070
commandLine.append(instance.GetInstanceId());
5171
#if defined(_M_ARM64)
52-
commandLine.append(LR"( -SkipAutomaticLocation -DevCmdArguments """-arch=arm64 -host_arch=x64"""}")");
72+
commandLine.append(LR"( -SkipAutomaticLocation -DevCmdArguments """-arch=arm64 -host_arch=arm64"""}")");
5373
#elif defined(_M_AMD64)
5474
commandLine.append(LR"( -SkipAutomaticLocation -DevCmdArguments """-arch=x64 -host_arch=x64"""}")");
5575
#else

0 commit comments

Comments
 (0)