I'm trying to run my first xUnit.net tests via MSBuild and I'm following the documentation here. Here is my project file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build;Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.msbuild.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.runner.msbuild.props"
Condition="Exists('..\packages\xunit.runner.msbuild.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.runner.msbuild.props')" />
<!--Extra lines omitted for brevity-->
<UsingTask AssemblyFile="xunit.runner.msbuild.dll"
TaskName="Xunit.Runner.MSBuild.xunit"/>
<Target Name="Test">
<xunit Assembly="bin\$(Configuration)\Core.dll"/>
</Target>
</Project>
When I run MSBuild, however, it gives me the following error:
C:\Users\James\libvideo\tests\Core\Core\Core.csproj(85,5):
error MSB4127: The "xunit" task could not be instantiated from the assembly "C:\Users\James\libvideo\tests\Core\packages\xunit.runner.msbuild.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.runner.msbuild.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 'Xunit.Runner.MSBuild.xunit' to type 'Microsoft.Build.Framework.ITask'.
I've checked that the spelling is correct, however it's still giving me this error. The xUnit.net documentation says nothing about this (or at least from where I've looked), so I'm stuck at what to do now. It tells me that I can check the version of MSBuild the assembly was built with, but how do I do that? Is MSBuild even required to build an assembly?
(MSBuild says it's version 14.0.23107.0, I have VS2015 if that's important.)
Thank you!
MSBuild is based on tasks and targets. You can see what it looks like in a .csproj, usually at the end. The task object is defined in the version of MSBuild you are using, located in, for example, C:\Program Files (x86)\MSBuild\12.0\Bin
.
Version of MSBuild typically follows the .NET framework like this:
version 1.0: 2006
version 2.0:
version 3.5: 2011
You probably miss the right version of MSBuild. Or you can try with a different version than ToolsVersion="14.0"
.