Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find `msbuild` using `vswhere`
use std::path::PathBuf;
use std::process::Command;
use std::str;
let mut msbuild = PathBuf::from("msbuild");
let check_msbuild = Command::new(msbuild)
.arg("--version")
.output()
.is_ok();
if !check_msbuild {
let vswhere = {
let mut path = PathBuf::from(std::env::var("ProgramFiles(x86)").expect("failed to find `vswhere`"));
path.push("Microsoft Visual Studio");
path.push("Installer");
path.push("vswhere.exe");
path
};
let msbuild_paths = Command::new(vswhere)
.args(&[
"-latest",
"-requires",
"Microsoft.Component.MSBuild",
"-find",
"MSBuild\\**\\Bin\\MSBuild.exe"
] as &[_])
.output()
.expect("failed to run vswhere");
let found_msbuild_path = str::from_utf8(&msbuild_paths.stdout)
.expect("invalid vswhere output")
.lines()
.next()
.expect("no vswhere output");
msbuild = PathBuf::from(found_msbuild_path);
} else {
panic!("on the path!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.