@@ -881,31 +881,40 @@ $vs_installs = ConvertFrom-Json "$(&$vswhere -version "$vs_major.0" -format 'jso
881
881
$vs_installer = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\setup.exe"
882
882
$vs_path = $vs_installs[0].installationPath
883
883
884
+ function install_msvc_comp($comp_id) {
885
+ Write-Host "Installing $comp_id into $vs_path ..."
886
+ &$vs_installer modify --quiet --installPath $vs_path --add $comp_id | Out-Host
887
+ if ($?) {
888
+ Write-Host "Install $comp_id success."
889
+ }
890
+ else {
891
+ Write-Error "Install $comp_id fail!"
892
+ exit 1
893
+ }
894
+ }
895
+
896
+ # msvc
884
897
$vs_arch = @{x64 = 'x86.x64'; x86 = 'x86.x64'; arm64 = 'ARM64'; arm = 'ARM' }[$arch]
885
898
$msvc_comp_id = "Microsoft.VisualStudio.Component.VC.$ver.$vs_ver.$vs_arch" # refer to: https://learn.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?view=vs-2022
886
- Write-Host "Installing $msvc_comp_id ..."
887
- &$vs_installer modify --quiet --installPath $vs_path --add $msvc_comp_id | Out-Host
899
+ install_msvc_comp $msvc_comp_id
888
900
889
- if ($?) {
890
- Write-Host "Install $msvc_comp_id success."
891
- }
892
- else {
893
- Write-Error "Install $msvc_comp_id fail!"
894
- exit 1
895
- }
901
+ # mfc
902
+ $suffix = @{x64 = ''; x86 = ''; arm64 = '.ARM64'; arm = '.ARM' }[$arch]
903
+ $mfc_comp_id = "Microsoft.VisualStudio.Component.VC.$ver.$vs_ver.MFC$suffix"
904
+ install_msvc_comp $mfc_comp_id
896
905
'@
897
- $1k.println (" Installing $ver ' , please press YES in UAC dialog, and don't close popup install window ..." )
906
+ $1k.println (" Installing $ver , please press YES in UAC dialog, and don't close popup install window ..." )
898
907
$__install_script = [System.IO.Path ]::GetTempFileName() + ' .ps1'
899
908
[System.IO.File ]::WriteAllText($__install_script , $__install_code )
900
909
$process = Start-Process powershell - ArgumentList " -File `"`" $__install_script `"`" -ver $ver -arch $arch " - Verb runas - PassThru - Wait
901
910
$install_ret = $process.ExitCode
902
911
[System.IO.File ]::Delete($__install_script )
903
912
904
913
if ($install_ret -eq 0 ) {
905
- $1k.println (" Install msvc-$ver ' succeed" )
914
+ $1k.println (" Install msvc-$ver succeed" )
906
915
}
907
916
else {
908
- throw " Install msvc-$ver ' fail!"
917
+ throw " Install msvc-$ver fail!"
909
918
}
910
919
}
911
920
@@ -1454,7 +1463,23 @@ function setup_msvc() {
1454
1463
if (! $manifest [' msvc' ].EndsWith(' +' )) { $dev_cmd_args += " -vcvars_ver=$cl_ver " }
1455
1464
1456
1465
Import-Module " $vs_path \Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
1457
- Enter-VsDevShell - VsInstanceId $Global :VS_INST.instanceId - SkipAutomaticLocation - DevCmdArguments $dev_cmd_args
1466
+ $1k.println (" Enter vs dev shell ..." )
1467
+ Enter-VsDevShell - VsInstanceId $Global :VS_INST.instanceId - SkipAutomaticLocation - DevCmdArguments $dev_cmd_args - ErrorAction SilentlyContinue
1468
+ if ($? ) {
1469
+ $1k.println (' Enter vs dev shell success.' )
1470
+ }
1471
+ else {
1472
+ # vs2022 x64,x86 share same msvc component
1473
+ install_msvc $cl_ver ' x64'
1474
+ $1k.println (" Enter vs dev shell ..." )
1475
+ Enter-VsDevShell - VsInstanceId $Global :VS_INST.instanceId - SkipAutomaticLocation - DevCmdArguments $dev_cmd_args - ErrorAction SilentlyContinue
1476
+ if ($? ) {
1477
+ $1k.println (' Enter vs dev shell success.' )
1478
+ }
1479
+ else {
1480
+ throw " Enter vs dev shell fail, please check your vs installation"
1481
+ }
1482
+ }
1458
1483
1459
1484
$cl_prog , $cl_ver = find_prog - name ' msvc' - cmd ' cl' - silent $true - usefv $true
1460
1485
$1k.println (" Using msvc: $cl_prog , version: $cl_ver " )
0 commit comments