c++visual-studiomsbuild

In Visual Studio Code 2017: msbuild : The term 'msbuild' is not recognized as the name of a cmdlet


 msbuild : The term 'msbuild' is not recognized as the name of a cmdlet,
 function, script file, or operable program.

As far as my googling goes, Visual Code should come with MSbuild. I have installed the C/C++ and msbuild Tools extensions to no avail. What can I do?

Edit: I am using Visual Studio Code 1.19.2


Solution

  • I suggest you rethink you command-line approach.

    Short plan

    1. Install Visual Studio Build Tools 2017
    2. Find proper MSBuild
    3. Use it

    Details

    1. Using Build Tools will give you independence from Visual Studio installation.

    Download Build Tools for Visual Studio 2017 (direct link)

    Command-line arguments documented here: Use command-line parameters to install Visual Studio 2017

    All workloads and components are listed here: Visual Studio Build Tools 2017 component directory

    1. You can use PowerShell module VSSetup. Download it or install from here: Github: Microsoft/Visual Studio Setup PowerShell Module

    2. Run MSBuild with build target (you can add additional required parameters)


    # 1. Find MS Build  
    
    Import-Module $PSScriptRoot\VSSetup\VSSetup.psd1
    
    $msBuildPath = (Get-VSSetupInstance | Select-VSSetupInstance -Version 15.0 -Product Microsoft.VisualStudio.Product.BuildTools).InstallationPath
    
    if ([System.IntPtr]::Size -eq 8)
    {
        $global:msbuildPath = Join-Path $msBuildPath 'MSBuild\15.0\Bin\amd64'
    }
    else
    {
        $global:msbuildPath = Join-Path $msBuildPath 'MSBuild\15.0\Bin'
    }
    
    Write-Output "Using MSBuild from $global:msbuildPath"
    Write-Output "MSBuild /version"
    
    $msbuild = Join-Path $global:msbuildPath msbuild
    
    & $msbuild /version
    
    # 2. Build
    
    & $msbuild "$sln_file" /t:Build /v:q /nologo