XUnit在MSBuild期间不工作

本文关键字:工作 MSBuild XUnit | 更新日期: 2023-09-27 18:09:06

我是Xunit的新手,我试图通过MSBuild运行它。下面是我到目前为止的构建脚本:

<UsingTask AssemblyFile="..'packages'xunit.runner.msbuild.*'build'*'xunit.runner.msbuild.dll"
           TaskName="Xunit.Runner.MSBuild.xunit"/>
<Target Name="Test">
    <xunit Assemblies="bin'$(Configuration)'Core.dll"/>
</Target>

当我在.csproj上运行MSBuild时,然而,它给了我以下错误:

error MSB4127: The "Xunit.Runner.MSBuild.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'.

我已经检查了它正在寻找的路径是否存在,并且我也遵循了这里的步骤。然而,运气不好。我能做些什么来解决这个问题?

XUnit在MSBuild期间不工作

此错误通常是由于MSBuild工具版本不匹配造成的。这在<Project>根元素中定义。您正在运行的工具版本来自不同于xunit运行器的ITask接口版本,因此如果没有程序集绑定重定向,它就不能在不同版本的ITask之间进行强制转换。

https://msdn.microsoft.com/en-us/library/bb383796.aspx