Skip to content

Fix visual c++ detection via vswhere #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

BurningEnlightenment
Copy link

@BurningEnlightenment BurningEnlightenment commented May 8, 2019

Implements vswhere detection as per #100 (comment) and vswhere wiki

Until now this has only been tested on a build server with VS build tools installed, but I will deploy this patch to a team with ~30 people in the coming weeks and report back how well it performed.

@nicole-mcg
Copy link
Contributor

nicole-mcg commented May 26, 2019

Here is my Python script that has been able to find MSBuild.exe on a number different windows 10 installations. It has worked for me with Visual Studio 2017 and 2019 and will use 2019 when both are installed. I haven't tested but I suspect it will work with 2015 as well. I created my own build step that includes generating and building with no configuration, but will be switching to cmake-js instead. Sharing this in case it comes in handy!

def find_ms_build():
    path = ""
    cmd = subprocess.Popen('"%ProgramFiles(x86)%/Microsoft Visual Studio/Installer/vswhere.exe" -nologo -latest -property installationPath', shell=True, stdout=subprocess.PIPE)
    for line in cmd.stdout:
        path = str(line).replace('b\'', '').replace('\\r\\n\'', '').replace('\\\\', '\\')

    return "{}/MSBuild/Current/Bin/MSBuild.exe".format(path)

EDIT:

Figured I may as well convert it to JS to make it a bit easier to use:

var exec = require('child_process').execSync;

function findMSBuild() {
    const replaceAll = (str, search, replacement="") => [...str.split(search)].join(replacement);

    const buffer = exec('"%ProgramFiles(x86)%/Microsoft Visual Studio/Installer/vswhere.exe" -nologo -latest -property installationPath');

    let path = buffer.toString();
    path = replaceAll(path, "\r", "");
    path = replaceAll(path, "\n", "");
    path = replaceAll(path, "\\r\\n", "");
    path = replaceAll(path, "\\\\", "/");
    path = replaceAll(path, "\\", "/");

    return path + "/MSBuild/Current/Bin/MSBuild.exe";
}

console.log(`Location of MSBuild.exe: '${findMSBuild()}'`);

@nicole-mcg
Copy link
Contributor

After looking into the code more I thought it would be best to open a new pull request with different changes #178

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants