()
| 405 | } |
| 406 | |
| 407 | func detectMSVCGenerator() (string, error) { |
| 408 | // Query all available msvc installation paths. |
| 409 | args := []string{ |
| 410 | "-products", "*", |
| 411 | "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", |
| 412 | "-property", "installationPath", |
| 413 | } |
| 414 | exector := cmd.NewExecutor("[detect msvc generator]", "vswhere", args...) |
| 415 | output, err := exector.ExecuteOutput() |
| 416 | if err != nil { |
| 417 | return "", err |
| 418 | } |
| 419 | |
| 420 | // Trim the output. |
| 421 | msvcDir := strings.TrimSpace(output) |
| 422 | if msvcDir == "" { |
| 423 | return "", fmt.Errorf("msvc not found, please install msvc first") |
| 424 | } |
| 425 | |
| 426 | // return msvc name. |
| 427 | switch { |
| 428 | case strings.Contains(msvcDir, "18"): |
| 429 | return visualStudio_18_2026, nil |
| 430 | case strings.Contains(msvcDir, "2022"): |
| 431 | return visualStudio_17_2022, nil |
| 432 | case strings.Contains(msvcDir, "2019"): |
| 433 | return visualStudio_16_2019, nil |
| 434 | case strings.Contains(msvcDir, "2017"): |
| 435 | return visualStudio_15_2017, nil |
| 436 | case strings.Contains(msvcDir, "2015"): |
| 437 | return visualStudio_14_2015, nil |
| 438 | default: |
| 439 | return "", fmt.Errorf("unsupported visual studio version: %s", msvcDir) |
| 440 | } |
| 441 | } |
no test coverage detected