Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild from command line errors - Reference required to System.Xml

Tags:

msbuild

I'm creating a batch script which will get latest version of the code of an application, then build it using msbuild. Everything works until the msbuild part. Here's the line that runs msbuild:

C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe "code/Solution.sln" /p:Configuration="Debug"

And the thing errors all over the place - all the errors say something like:

C:\code\project1\codefile1.vb(882): error BC30009: Reference required to assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' containing the implemented interface 'System.Xml.Serialization.IXmlSerializable'. Add one to your project.

Everything builds without errors from from Visual Studio 2008. What's going on here?

like image 955
Brandon Montgomery Avatar asked Nov 05 '10 13:11

Brandon Montgomery


People also ask

How do I run MSBuild from command line?

To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.

How do I get MSBuild command from 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.

How do I add MSBuild exe to path?

Click on System and Security and then on System. In the left pane, click on Advanced system settings. At the very bottom of the pop up, click on Environment Variables. Edit the Path variable and append the folder's path that contains the MSBuild.exe to it (e.g., ;C:\Windows\Microsoft.NET\Framework64\v4.

How do you clean MSBuild solution?

Cleaning up specific projects: msbuild MyProjectFile1 /t:Clean msbuild MyProjectFile2 /t:Clean ... This has to be repeated for all projects you need to clean, because MSBuild only accepts single project on command line.


2 Answers

This is probably most detailed descriptions on what is going wrong:

MSBuild Can't Find Secondary References

Resolving Binary References in MSBuild

In short: Your project references assembly X. X contains a class, that implements interface from assembly Y. Your project does not reference Y, so MSBuild fails. Studio acts a bit smarter and finds the second level reference.

like image 119
Bohumil Janda Avatar answered Oct 20 '22 02:10

Bohumil Janda


Do just what it says and add a reference to System.Xml to your project.

Project->Add Reference

like image 38
amjad qureshi Avatar answered Oct 20 '22 02:10

amjad qureshi