Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/VsDevShellGenerator.cpp (C++)

Code before:
        profile->Name(winrt::hstring{ GetProfileName(instance) });
        profile->Commandline(winrt::hstring{ GetProfileCommandLine(instance) });
        profile->StartingDirectory(winrt::hstring{ instance.GetInstallationPath() });
        profile->Icon(winrt::hstring{ GetProfileIconPath() });
        profile->Hidden(hidden);
        profiles.emplace_back(std::move(profile));
    }
    CATCH_LOG();
}

std::wstring VsDevShellGenerator::GetProfileName(const VsSetupConfiguration::VsSetupInstance& instance) const
{
    std::wstring name{ L"Developer PowerShell for VS " };
    name.append(instance.GetProfileNameSuffix());
    return name;
}

std::wstring VsDevShellGenerator::GetProfileCommandLine(const VsSetupConfiguration::VsSetupInstance& instance) const
{
    // Build this in stages, so reserve space now
    std::wstring commandLine;
    commandLine.reserve(256);

    // Try to detect if `pwsh.exe` is available in the PATH, if so we want to use that
    // Allow some extra space in case user put it somewhere odd
    // We do need to allocate space for the full path even if we don't want to paste the whole thing in
    wchar_t pwshPath[MAX_PATH] = { 0 };
    const auto pwshExeName = L"pwsh.exe";
    if (SearchPathW(nullptr, pwshExeName, nullptr, MAX_PATH, pwshPath, nullptr))
    {
        commandLine.append(pwshExeName);
    }
    else
    {
        commandLine.append(L"powershell.exe");
    }


    // The triple-quotes are a PowerShell path escape sequence that can safely be stored in a JSON object.
    // The "SkipAutomaticLocation" parameter will prevent "Enter-VsDevShell" from automatically setting the shell path
    // so the path in the profile will be used instead
    commandLine.append(LR"( -NoExit -Command "&{Import-Module """)");
    commandLine.append(GetDevShellModulePath(instance));
    commandLine.append(LR"("""; Enter-VsDevShell )");
    commandLine.append(instance.GetInstanceId());
#if defined(_M_ARM64)
    commandLine.append(LR"( -SkipAutomaticLocation -DevCmdArguments """-arch=arm64 -host_arch=arm64"""}")");
#elif defined(_M_AMD64)
    commandLine.append(LR"( -SkipAutomaticLocation -DevCmdArguments """-arch=x64 -host_arch=x64"""}")");
#else
    commandLine.append(LR"( -SkipAutomaticLocation}")");

Review comment (refactor):
I was gonna suggest simplifying this with `wil::SearchPathW`, but we actually aren't using the path we get at all... so that's fine as-is

Code after:
        profile->Icon(winrt::hstring{ GetProfileIconPath() });
        profile->Hidden(hidden);
        profiles.emplace_back(std::move(profile));
    }
    CATCH_LOG();
}

std::wstring VsDevShellGenerator::GetProfileName(const VsSetupConfiguration::VsSetupInstance& instance) const
{
    std::wstring name{ L"Developer PowerShell for VS " };
    name.append(instance.GetProfileNameSuffix());
    return name;
}

std::wstring VsDevShellGenerator::GetProfileCommandLine(const VsSetupConfiguration::VsSetupInstance& instance) const
{
    // Build this in stages, so reserve space now
    std::wstring commandLine;
    commandLine.reserve(256);

    // Try to detect if `pwsh.exe` is available in the PATH, if so we want to use that
    // Allow some extra space in case user put it somewhere odd
    // We do need to allocate space for the full path even if we don't want to paste the whole thing in
    wchar_t pwshPath[MAX_PATH] = { 0 };
    const auto pwshExeName = L"pwsh.exe";
    if (SearchPathW(nullptr, pwshExeName, nullptr, MAX_PATH, pwshPath, nullptr))
    {
        commandLine.append(pwshExeName);
    }
    else
    {
        commandLine.append(L"powershell.exe");
    }

    // The triple-quotes are a PowerShell path escape sequence that can safely be stored in a JSON object.
    // The "SkipAutomaticLocation" parameter will prevent "Enter-VsDevShell" from automatically setting the shell path
    // so the path in the profile will be used instead
    commandLine.append(LR"( -NoExit -Command "&{Import-Module """)");
    commandLine.append(GetDevShellModulePath(instance));
    commandLine.append(LR"("""; Enter-VsDevShell )");
    commandLine.append(instance.GetInstanceId());
#if defined(_M_ARM64)
    // This part stays constant no matter what
    commandLine.append(LR"( -SkipAutomaticLocation -DevCmdArguments """-arch=arm64 -host_arch=)");
    if (instance.VersionInRange(L"[17.4,"))
    {
        commandLine.append(LR"("arm64 """}")");
    }
    // If an old version of VS is installed without ARM64 host support
    else
    {