Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 493
Daniel Paczuski Bak Avatar asked Jan 19 '18 21:01

Daniel Paczuski Bak


People also ask

How do I enable MSBuild?

To enable msbuild in Command Prompt, you simply have to add the directory of the msbuild.exe install on your machine to the PATH environment variable. You can access the environment variables by: Right clicking on Computer. Click Properties.

Does Visual Studio code come with MSBuild?

If you have Visual Studio, then you already have MSBuild installed. With Visual Studio 2019 and later, it's installed under the Visual Studio installation folder. For a typical default installation on Windows 10, MSBuild.exe is under the installation folder in MSBuild\Current\Bin.

What MSBuild command does Visual Studio use?

Visual Studio uses MSBuild to load and build managed projects. The project files in Visual Studio (. csproj, . vbproj, .

How do I add MSBuild exe to path?

Click on System and Security and then on System. In the left pane, click on Advanced system settings. At the very bottom of the pop up, click on Environment Variables. Edit the Path variable and append the folder's path that contains the MSBuild.exe to it (e.g., ;C:\Windows\Microsoft.NET\Framework64\v4.


1 Answers

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 from Visual Studio Downloads page (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

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

  3. 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 
like image 87
Vlad DX Avatar answered Sep 29 '22 02:09

Vlad DX