microsoft/typespec
Publicmirrored from https://github.com/microsoft/typespecAvailable
packages/internal-build-utils/src/visualstudio.ts
36lines · modecode
| 1 | import { join } from "path"; |
| 2 | import { run } from "./common.js"; |
| 3 | import { vsMinimumVersion } from "./constants.js"; |
| 4 | |
| 5 | const vswhereArgs = [ |
| 6 | "-latest", |
| 7 | "-prerelease", |
| 8 | "-version", |
| 9 | `[${vsMinimumVersion},`, |
| 10 | "-property", |
| 11 | "installationPath", |
| 12 | ]; |
| 13 | |
| 14 | export async function getVisualStudioMsBuildPath(): Promise<{ path: string } | { error: string }> { |
| 15 | if (process.platform !== "win32") { |
| 16 | return { error: "Not on windows." }; |
| 17 | } |
| 18 | |
| 19 | const vswhere = join( |
| 20 | process.env["ProgramFiles(x86)"]!, |
| 21 | "Microsoft Visual Studio/Installer/vswhere.exe" |
| 22 | ); |
| 23 | |
| 24 | const result = await run(vswhere, vswhereArgs, { |
| 25 | ignoreCommandNotFound: true, |
| 26 | throwOnNonZeroExit: false, |
| 27 | encoding: "utf-8", |
| 28 | stdio: [null, "pipe", "inherit"], |
| 29 | }); |
| 30 | |
| 31 | if (!result || result.exitCode !== 0 || !result.stdout) { |
| 32 | return { error: `Visual Studio ${vsMinimumVersion} or later not found` }; |
| 33 | } |
| 34 | |
| 35 | return { path: join(result.stdout.trim(), "MSBuild/Current/Bin/MSBuild.exe") }; |
| 36 | } |
| 37 | |