|
8 | 8 |
|
9 | 9 | using namespace winrt::Microsoft::Terminal::Settings::Model;
|
10 | 10 |
|
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 |
12 | 15 | {
|
13 | 16 | try
|
14 | 17 | {
|
@@ -39,17 +42,34 @@ std::wstring VsDevShellGenerator::GetProfileName(const VsSetupConfiguration::VsS
|
39 | 42 |
|
40 | 43 | std::wstring VsDevShellGenerator::GetProfileCommandLine(const VsSetupConfiguration::VsSetupInstance& instance) const
|
41 | 44 | {
|
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 |
45 | 46 | std::wstring commandLine;
|
46 | 47 | 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 """)"); |
48 | 68 | commandLine.append(GetDevShellModulePath(instance));
|
49 | 69 | commandLine.append(LR"("""; Enter-VsDevShell )");
|
50 | 70 | commandLine.append(instance.GetInstanceId());
|
51 | 71 | #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"""}")"); |
53 | 73 | #elif defined(_M_AMD64)
|
54 | 74 | commandLine.append(LR"( -SkipAutomaticLocation -DevCmdArguments """-arch=x64 -host_arch=x64"""}")");
|
55 | 75 | #else
|
|
0 commit comments