Visual Studio build successful, MSBuild fails

后端 未结 7 2438
有刺的猬
有刺的猬 2021-02-19 02:08

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

相关标签:
7条回答
  • 2021-02-19 02:19

    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.

    0 讨论(0)
  • 2021-02-19 02:24

    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.

    0 讨论(0)
  • 2021-02-19 02:25

    In my case I had one PCL referencing another PCL with different targets. Visual Studio showed me a warning in the references list of the first library, but compiled the solution, whereas MSBUILD refused to compile. I fixed the problem by retargeting the PCL. Hope this helps somebody.

    0 讨论(0)
  • 2021-02-19 02:36

    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.

    0 讨论(0)
  • 2021-02-19 02:43

    Summary: Set Debug/Release mode in Visual Studio to the same settings as MSBuild to check for compilation errors.

    I encountered the same problem:

    • Tried deleting all "bin" and "obj" folders.

    • Made sure all related projects are indeed being referenced and not just liked to compiled dlls. ex. Project B references A. Remove A from solution. Then add again. B would then reference A but via compiled dll only. Remove reference and re-add the project.

    Finally switched to "Release" in Visual Studio. Turns out I had conditional compilation in some code (eg. #if DEBUG). So what was running in MSBuild and Visual Studio were actually different hence the error "The type or namespace name 'foo' does not exist in the namespace 'bar' (are you missing an assembly reference?)"

    0 讨论(0)
  • 2021-02-19 02:45

    For me the problem was that the some projects in the solution were not included in the build configuration for the solution. Those projects were dependencies for the projects in the build configuration, so all the projects in the solution failed.

    After marking the dependcies projects with build in the solution configuration the msbuild ran successfully.

    0 讨论(0)
提交回复
热议问题