MSBuild may build projects in unexpected order with MSBuild project task, leading to errors like CS0006

Article translations Article translations
Close Close
Article ID: 964125 - View products that this article applies to.
Expand all | Collapse all
Source: Microsoft Support

RAPID PUBLISHING

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.

Action

You use MSBuild on the command line and pass an XML file containing the build project.  Rather than building a .sln directly, the XML project file contains an MSBuild task. Specify /p:platform=[some platform name] or /p:configuration=[some configuration name] in the command line, or specify these as global properties to the MSBuild task.

Result

The following, or similar, error may be thrown:
CSC : error CS0006: Metadata file '…\<dependency_file_name>' could not be found.

Cause



If the platform or configuration name properties are not found in the solution file, the step of scanning for dependencies is skipped.  Thus, the dependency relationships are not maintained and projects may build out of order.

MSBuild produces the temporary solution object with everything at the same dependency level, then builds it with the properties specified.

Resolution



There are several workarounds available depending on different scenarios:

1. Modify the solution file (which may contain a mixture of project types) so that it contains a configuration that matches the name to be passed on the command line.

2. In the .xml file, instead of using the MSBuild task, use the Exec task to launch msbuild.exe on the solution.The potential disadvantages of this are that logging won’t work so well. Also the multiprocessor build will not be synchronised.

3. Build the solution file directly, i.e. msbuild.exe mysolution.sln /p:xx=yy ... without an .xml file involved.

4. Build all the projects in the solution with the MSBuild task in the .xml file instead of building the .sln file.

More Information

MSBuild Command Line Reference
MSBuild Project File Schema Reference

DISCLAIMER

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.

Properties

Article ID: 964125 - Last Review: January 22, 2009 - Revision: 1.0
APPLIES TO
  • Microsoft Visual Studio 2008 Standard Edition
  • Microsoft Visual Studio 2008 Professional Edition
  • Microsoft Visual Studio Team System 2008 Team Suite
  • Microsoft Visual Studio 2008 Service Pack 1
Keywords: 
kbnomt kbrapidpub KB964125

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com