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?


I just had to deal with this issue and it turns out that msbuild likes to move built binaries into the binariesrelease 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.


Try checking the paths to the references that MSBuild can't find in the non-building library's project file. Sometimes when you use VS or ReSharper to automatically add a reference for you the path ends up being to the obj directory. VS seems able to cope with this, but MSBuild not so much.


I assume there's a difference in how the project is built, because Visual Studio does not run MSBuild, as it rather hosts the build engine itself. This was answered here.

However, I've had similar problem.

In my case the project referenced an external library, which was placed in the project's child directory, unluckily named "packages".

After running MSBuild the folder's content was deleted, supposedly to be downloaded again by Nuget.

The obvious solution was to rename the folder and it worked.

链接地址: http://www.djcxy.com/p/80124.html

上一篇: 使Struts 2与Java 8(传统ASM 3)兼容

下一篇: Visual Studio构建成功,MSBuild失败