Stew C
Stew C

Reputation: 758

Powershell MSBuild error

I am trying to convert some of my old batch files that run MSBuild into PowerShell scripts. Researching the Invoke-MSBuild command, the code below is what I came up with:

Invoke-MsBuild -Path "C:\path\solution.sln" -MsBuildParameters "/target:Clean;Rebuild /property:Configuration=Release;Platform=""x64"" /fl /flp:verbosity=normal;logfile=C:\path\logfile.log" -KeepBuildLogOnSuccessfulBuilds

Looking at the log file, when I run the script it starts building the solution file with MSBuild but I keep getting this error:

error MSB8020: The builds tools for v120 (Platform Toolset = 'v120') cannot be found. To build using the v120 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install v120 to build using the v120 build tools.

I am very confused because I have Visual Studio 2013 which uses the 12.0 platform. I tried reinstalling the v120 build tools but nothing changed.

Upvotes: 1

Views: 920

Answers (1)

NextInLine
NextInLine

Reputation: 2204

It's likely your PowerShell environment does not contain the proper environment variables (particularly %PATH%, or $env:Path in PowerShell). Fortunately, it's easy to confirm this is the case:

  • Open the Visual Studio 2013 command prompt
  • Run powershell
  • Run your Invoke-MsBuild command

If it runs using those steps, then your solution is either:

  1. Fiddle with powershell environment by editing your profile file (run $profile in powershell to find the path). For instance, the path can be modified by adding the line $env:Path = $env:Path + ';another_path;yet_another_path'

  2. Find the batch file that is called by the Visual Studio 2013 command prompt - create a new batch file that calls that, then invokes powershell, so that your powershell environment is configured before powershell actually runs.

Upvotes: 1

Related Questions