microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
a6b7827fcd2db3bf604d42e235216c8d5b244f13

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/internal-build-utils/src/visualstudio.ts

36lines · modecode

1import { join } from "path";
2import { run } from "./common.js";
3import { vsMinimumVersion } from "./constants.js";
4
5const vswhereArgs = [
6 "-latest",
7 "-prerelease",
8 "-version",
9 `[${vsMinimumVersion},`,
10 "-property",
11 "installationPath",
12];
13
14export 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