Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2013 and MSBuild

I've recently upgraded to Visual Studio 2013, which has caused back to back problems when building externally using MSBuild (API or Executable with command line args)

Issue #1 When building with MSBuild it doesn't generate Fake assemblies which are required for our Unit Tests, this leads to build failures. A simple build in visual studio fixes this temporarily, until a new fake assembly needs to be generated.

Issue #2 When running code analysis this complains with the following:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(284,5): 
error MSB4127: The "CodeAnalysis" task could not be instantiated from the assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\.\FxCopTask.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 'Microsoft.Build.Tasks.CodeAnalysis' to type 'Microsoft.Build.Framework.ITask'.

I only have Visual Studio 2013 installed on my machine, apparently installing an older version could fix the issue, but it's not something which I can do. (VS 2013 Ships with its own MSBuild 12.0 which is located in a different directory to the previous MSBuild).

I'm unsure why Visual Studio is behaving any differently to MSBuild, i'm simply pointing to the solution file like so...

msbuild.exe "path\solution.sln" /property:Configuration=Debug
like image 328
Jack Avatar asked May 06 '14 14:05

Jack


People also ask

Does Visual Studio include MSBuild?

If you have Visual Studio, then you already have MSBuild installed. With Visual Studio 2019 and later, it's installed under the Visual Studio installation folder. For a typical default installation on Windows 10, MSBuild.exe is under the installation folder in MSBuild\Current\Bin.

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.

Where is MSBuild for VS 2015?

1>C:\Program Files (x86)\MSBuild\Microsoft. Cpp\v4. 0\Platforms\Win32\Microsoft. Cpp.

Does MSBuild require Visual Studio license?

Use of the Build Tools require a valid Visual Studio license. If you can use the Visual Studio Community for free, you can also use the Build Tools with a valid free license. If you cannot use the Visual Studio Community, you need to use the Build Tools with a valid paid license.

Is MSBuild available in Visual Studio 2013?

MSBuild and the VB/C# compilers are now available as a standalone package, Microsoft® Build Tools. This package is installed with Visual Studio 2013.

What compilers does Visual Studio 2013 use?

Visual Studio 2013 will exclusively use 2013 MSBuild and VB/C# compilers (assembly version 12.0) and the 2013 Toolset (ToolsVersion 12.0). The way MSBuild selects Toolset versions for command line builds is now identical to the way Visual Studio builds projects. If your projects build in VS, they will build from the command line.

What is the Microsoft Build Engine (MSBuild)?

The Microsoft Build Engine is a platform for building applications. This engine, which is also known as MSBuild, provides an XML schema for a project file that controls how the build platform processes and builds software. Visual Studio uses MSBuild, but it doesn't depend on Visual Studio.

What's new With MSBuild's versioning?

We are simplifying MSBuild’s versioning story. Each version of Visual Studio will have a corresponding version of the Microsoft® Build Tools including MSBuild, the VB/C# compilers, and common tasks and targets that make up the 2013 Toolset. There will no longer be any sub Toolset versions.


1 Answers

So, Visual Studio 2013 comes with a new version of MSBuild i.e. MSBuild 12.0. Once installed, it changes the path so that the new version is used by default.

Looks like your solution compiles with visual studio 2012, you can either specify the full path to msbuild.exe such as

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild "path\solution.sln" /property:Configuration=Debug

or set the visual studio 2012 environment variables by running the following before executing msbuild

"%VS110COMNTOOLS%"\vsvars32.bat // VS2012 environment variables

EDIT: Using MSbuild 12.0 assemblies "C:\Program Files (x86)\MSBuild\12.0\Bin\" fixes the issue with the code Analysis bug.

like image 175
Hamid Shahid Avatar answered Oct 24 '22 22:10

Hamid Shahid