Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the version of MSBuild an assembly was built with?

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!

like image 689
James Ko Avatar asked Aug 22 '15 14:08

James Ko


People also ask

How do I check MSBuild Tools version?

Starting in Visual Studio 2013, the MSBuild Toolset version is the same as the Visual Studio version number. MSBuild defaults to this Toolset within Visual Studio and on the command line, regardless of the Toolset version specified in the project file. This behavior can be overridden by using the -ToolsVersion flag.

Does Visual Studio call MSBuild?

Visual Studio uses MSBuild, but MSBuild doesn't depend on Visual Studio. By invoking msbuild.exe on your project or solution file, you can orchestrate and build products in environments where Visual Studio isn't installed.

What is the difference between MSBuild and Visual Studio build?

Visual Studio determines the build order and calls into MSBuild separately (as needed), all completely under Visual Studio's control. Another difference arises when MSBuild is invoked with a solution file, MSBuild parses the solution file, creates a standard XML input file, evaluates it, and executes it as a project.


1 Answers

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".

like image 197
dolomitt Avatar answered Sep 22 '22 17:09

dolomitt