Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio build successful, MSBuild fails

I am trying to clean and rebuild a solution file with multiple projects from the command line using MSBUILD. For some reason my build fails (about 10% of the built projects fail) and I get multiple errors which all look like:

error CS0234: The type or namespace name 'foo' does not exist in the namespace 'bar' (are you missing an assembly reference?)

Now if I clean and rebuild the same solution file from Visual Studio 2010 with the exact same configurations it will build successfully with no errors.

Is there a difference in the setup or configuration of MSBuild from Visual Studio that needs to be changed that I am not aware of?

like image 952
Stew C Avatar asked Jun 27 '14 18:06

Stew C


People also ask

How do I fix build failed error in Visual Studio?

In Visual Studio 2019 Update 16.5 or later you can go to Tools > Options > Projects and Solutions > Build and Run and set 'On Run, when build or deployment error occurs' to one of the options below. Once this is set, running and debugging tests will honor this option as well.

How do I run MSBuild in Visual Studio?

To install MSBuild on a system that doesn't have Visual Studio, go to Build Tools for Visual Studio 2019, or install the . NET SDK. If you have Visual Studio, then you already have MSBuild installed. With Visual Studio 2022, it's installed under the Visual Studio installation folder.

Does Visual Studio call MSBuild?

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

Is it possible to build an application on a system if MSBuild is not installed?

Is it possible to build an application on a system if the MSBuild is not installed? If so, How? Yes, it is actually possible because the MSBuild doesn't depend on the Visual Studio of its operations.


1 Answers

I just had to deal with this issue and it turns out that msbuild likes to move built binaries into the binaries\release directory and reference those instead of the projects themselves when it builds things. After building it copies the files to this directory. This explains why it works in visual studio and not msbuild (I'm currently using TFS 1010).

In my case I had an old binary version of a dll being referenced by a project that was being built after the one that should have generated the correct file. The old one (binary) was overwriting the new one (built from source) as the solution referencing the binary one was being built later in the build.

like image 155
Mike Cheel Avatar answered Oct 04 '22 01:10

Mike Cheel