Bug 6708 - xbuild adds too many reference arguments when building projects
Summary: xbuild adds too many reference arguments when building projects
Status: RESOLVED FIXED
Alias: None
Product: Tools
Classification: Mono
Component: xbuild ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Alan McGovern
URL:
Depends on:
Blocks:
 
Reported: 2012-08-27 11:57 UTC by Stephen McConnel
Modified: 2012-08-29 09:06 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Proposed patch to fix the problem (2.91 KB, patch)
2012-08-27 11:57 UTC, Stephen McConnel
Details
test program to demonstrate the bug (9.43 KB, application/zip)
2012-08-27 13:46 UTC, Stephen McConnel
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Stephen McConnel 2012-08-27 11:57:57 UTC
Created attachment 2416 [details]
Proposed patch to fix the problem

xbuild adds dependencies of references to the command line when it builds a project.  Neither MonoDevelop nor msbuild on Windows does this.  This can cause problems if there's a clash between static classes and namespaces revealed by loading a dependent assembly that isn't otherwise referenced directly.
Comment 1 Mikayla Hutchinson [MSFT] 2012-08-27 12:10:16 UTC
I don't think it's that simple, IIRC the MS targets sets FindDependencies true in most cases.

I think  Alan looked at this already - any comments?
Comment 2 Alan McGovern 2012-08-27 12:20:33 UTC
I attempted a similar fix a few weeks ago but when I checked against msbuild, i realised that it was incorrect. The value of 'FindDependencies' should (and is) set to true in this case.

I've been trying to find a small sample which demonstrates the incorrect behavior which can be turned into an xbuild unit test, but I have been unable to create a failing unit test so far. If you can figure out a small testcase which demonstrates the issue, that'd be the best way to get this fixed.
Comment 3 Stephen McConnel 2012-08-27 12:26:06 UTC
I know the fixes to the .targets file were rather simplistic (but the setting to true was also rather simplistic compared to what msbuild has), but I think the code change to the .cs file is good.  I'll try to simplify our code down to a reasonable test case to demonstrate the problem in practice.
Comment 4 Stephen McConnel 2012-08-27 13:46:49 UTC
Created attachment 2418 [details]
test program to demonstrate the bug

The attached zip file contains a set of four projects with a master project file (BugTest.proj) that demonstrates the bug.  This project file builds perfectly fine on Windows using msbuild.exe, but fails using xbuild (on Linux).
Comment 5 Alan McGovern 2012-08-28 07:39:21 UTC
The attached solution does not compile with msbuild or xbuild. Are you sure you attached the right thing?
Comment 6 Alan McGovern 2012-08-28 07:40:38 UTC
Maybe I'm just building it wrong. What command should I be running to replicate the correct failure?
Comment 7 Stephen McConnel 2012-08-28 10:58:41 UTC
The solution file (XbuildReferenceBugTest.sln) won't work to build the attached project with either msbuild or xbuild because I created it using MonoDevelop, and MonoDevelop doesn't allow you to specify dependencies.  It compiled fine for me on Windows using msbuild from VS 10 using the BugTest.proj file explicitly like this:

msbuild BugTest.proj

But building the projects fails using xbuild on Linux:

xbuild BugTest.proj

The solution file perhaps should be deleted since it doesn't help with tracing the xbuild bug.

Since our build process involves almost 200 projects, with both C# and C++ code, and a number of specialized operations, we don't try to create a solution file per se, but instead create a master project file to control building the whole system.
Comment 8 Alan McGovern 2012-08-28 11:00:29 UTC
I have the testcase reduced down to the bare minimum now and have tracked down the exact variable which is incorrect. If all goes well I should have the correct fix in a little while. Thanks a lot for the attached solution, it was perfect!
Comment 9 Alan McGovern 2012-08-29 09:06:13 UTC
Fixed in commit 2e7acd75fda3a3cf5fddca4bd71743caf43aa06c in mono/master. I took the compiled binaries from the solution you provided and created a few unit tests out of them to validate the fix. There are still some issues with gathering LocalCopy files, specifically pdb/mdb debug files, but I'll fix that separately.