error MSB4127 "Message" task could not be instantiated from Microsoft.Build.Tasks.Core
A colleague encountered an issue using our build automation scripts. A repro in a nutshell is as follows:
$solution = 'c:\path\to\moirai\tests\moirai_test.sln'
$debugCfg = 'Debug'
$buildConfiguration = $debugCfg
$buildPlatform = "x64"
$buildMode = 'Rebuild'
$toolsVersion = '14.0'
$env:MSBuildEmitSolution = 1; # Keep generated metaproj files
$detailedLogFile = "c:\tmp\builddiagnostics.txt"
$logger = New-FileLogger -Verbosity Diagnostic -DisableConsoleColor -LogFile $detailedLogFile
Invoke-MSBuild -Project $solution -Target $buildMode -Verbosity Diagnostic -Logger $logger -Property @{Configuration=$buildConfiguration;Platform=$buildPlatform} -ToolsVersion $toolsVersion
The build fails with:
c:\src\github_jm\moirai\tests\moirai_test.sln.metaproj : error MSB4127: The "Message" task could not be
instantiated from the assembly "Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a". Please verify the task assembly has been built using the same
version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your
host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of
type 'Microsoft.Build.Tasks.Message' to type 'Microsoft.Build.Framework.ITask'.
Further context:
Windows 10,
VS110COMNTOOLS = C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\
VS120COMNTOOLS = C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
and has msbuild toolchains:
C:\Program Files (x86)\Reference Assemblies\Microsoft\MSBuild\v12.0
C:\Program Files (x86)\Reference Assemblies\Microsoft\MSBuild\v14.0
It works for me, with similar setup but Win7 and an additional "C:\Program Files (x86)\Microsoft Visual Studio 14.0" but I doubt these are crucial differences.
I suspect this is related to PowerBuild:issue 9.
I am trying to capture further information using fuslogvw.exe and will follow up with additional information if relevant.
What versions of Visual studio have your colleague installed?
Also you can use -Configuration and -Platform parameters instead of -Property.
VS 2013 and VS 2012 ( corresponding to the VS120COMNTOOLS and VS110COMNTOOLS environment variables)
So far I've been testing in only on systems with VS2017 installed. So I'm not 100% if this going to work, but could you try set $env:MSBUILD_EXE_PATH to full path of msbuilld,exe. Right after starting PS host, before loading PowerBuild assemblies.