The error above happens with VS 2017 15.5.2 in a test project while executing the following test. There are binding redirects in the test.vbproj file but nothing for msbuild.
<TestMethod()> Public Sub ElementTypeUnitTestAsync()
Dim RoslynPath As String = Path.Combine(RepoPath, SolutionPartialPath)
Dim MS_Workspace As MSBuildWorkspace = MSBuildWorkspace.Create()
AddHandler MS_Workspace.WorkspaceFailed, Sub(sender As Object, e As WorkspaceDiagnosticEventArgs)
Debug.WriteLine(e.Diagnostic.ToString())
End Sub
Dim NewSolution As Solution = MS_Workspace.OpenSolutionAsync(RoslynPath).Result
End Sub
The whole message is
[Failure] Msbuild failed when processing the file 'C:\Repos\roslyn-master\src\Samples\CSharp\APISampleUnitTests\APISampleUnitTestsCS.csproj' with message: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets: (1601, 5): The "GetReferenceNearestTargetFrameworkTask" task could not be instantiated from the assembly "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.Build.Tasks.dll". 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 'NuGet.Build.Tasks.GetReferenceNearestTargetFrameworkTask' to type 'Microsoft.Build.Framework.ITask'. C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets: (1601, 5): The "GetReferenceNearestTargetFrameworkTask" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.
Microsoft.Build.Framework
assembly not being correct. Which version ofMicrosoft.Build.Framework
you are using in the project? Have you try to use other version? – Leo Liu-MSFTMicrosoft.Build.Framework
? I could not reproduce this issue, if you can reproduce the problem stably, could you please share me a simple sample, so I could reproduce this issue on my side? – Joy