Bug 22553 - Included projects not properly handled by Xamarin.
Summary: Included projects not properly handled by Xamarin.
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Project Model ()
Version: 5.2
Hardware: PC Windows
: Normal normal
Target Milestone: master
Assignee: Lluis Sanchez
Depends on:
Reported: 2014-09-01 16:14 UTC by David Naylor
Modified: 2014-09-03 09:20 UTC (History)
2 users (show)

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

Common project preamble (1.61 KB, application/octet-stream)
2014-09-01 16:15 UTC, David Naylor
Common project postamble (1.04 KB, application/octet-stream)
2014-09-01 16:15 UTC, David Naylor
Example project file (with workaround for issue 1, 4, 5) (1.65 KB, application/octet-stream)
2014-09-01 16:17 UTC, David Naylor
Full example (8.98 KB, application/x-zip-compressed)
2014-09-03 03:34 UTC, David Naylor

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 Developer Community or GitHub 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:

Description David Naylor 2014-09-01 16:14:29 UTC

I am using hand-written .csproj and .targets file to build the projects in a solution.  The intention is to have all the common code in the .targets files and only project specific code in the .csproj.  

An example layout is:
<... />

It appears - however - that Xamarin does not pick up some of the content from the included .target files.  Specifically Xamarin seems to ignore:
 - PropertyGroup/OutputDir [1]
 - PropertyGroup/PlatformTarget [2]
 - PropertyGroup [3] (conditional)
 - ItemGroup/Compile (with wildcards) [4]
 - ItemGroup/Reference [5]
 - Target [6]

[1] OutputDir appears to be inconsistently picked up.  The first project (a library) does use the correct OutputDir while the second project (a WinExe) uses the default 'bin\Debug' output.
[2] PlatformTarget appears to be quite complicated and only included for completeness.  
[3] The builder does correctly detect the compile target (with conditions) however the GUI does not pick up the files from the included project (it does pick up the files if included in the project .csproj file)
[4] Properties defined in a conditional PropertyGroup does not appear to be picked up by the build system.
[5] The builder does correctly detect the references however the GUI inconsistently picks up the references.  The references are not listed in the projects reference but the editor does not complain about a missing reference - and intelisence does work.  Also, the unit test running does not detect the nunit assembly unless included in the .csproj file.  
[6] All targets defined in a .targets file appear to be ignored.
Comment 1 David Naylor 2014-09-01 16:15:06 UTC
Created attachment 7879 [details]
Common project preamble
Comment 2 David Naylor 2014-09-01 16:15:31 UTC
Created attachment 7880 [details]
Common project postamble
Comment 3 David Naylor 2014-09-01 16:17:24 UTC
Created attachment 7881 [details]
Example project file (with workaround for issue 1, 4, 5)
Comment 4 Rajneesh Kumar 2014-09-02 08:27:34 UTC
I have checked this issue and not able to reproduce this. To reproduce this I used the sample project and help provided in the bug description. Steps I have try to reproduce:

1. Open attached "Example Project File" in XS
2. It has a number of project in it.
3. Try to compile the solution it has build error
   "C:\Users\Admin\DTT.Common.per.targets" was not found.
4. Download Attached "Common project preamble" and "Common project postamble"
5. Paste it in to "C:\Users\Admin"
6. Error described in line 3 will remove and new error will occur
   \StyleComp.MSBuild.Targets" was not found.
7. I go through this path "C:\Users\admin\Downloads\" but but could't find such folders.

Please let me know that you are facing the same experience or not. If not, then please let me know if I am missing something anywhere else to reproduce this issue, and could you please provide us the steps to reproduce this issue ? That will be helpful to reproduce this issue at our end. Please refer the Screencast: http://www.screencast.com/t/rD4SvVaDx

Environment Info:

=== Xamarin Studio ===

Version 5.2 (build 386)
Installation UUID: 3b924754-5196-440a-b42b-05ebb3a3082e
	Microsoft .NET 4.0.30319.18408
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

=== Xamarin.Android ===

Version: 4.14.0 (Business Edition)
Android SDK: D:\Android\android-sdk
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: C:\Program Files\Java\jdk1.6.0_31
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) Client VM (build 20.6-b01, mixed mode, sharing)

=== Build Information ===

Release ID: 502000386
Git revision: e6a54dee5376e6e7a2d9982695b060fddc09e65d
Build date: 2014-08-04 14:07:09-04
Xamarin addins: 2b5a5c26ac2ee74c6e91a8d24ef44d0ca9cb74d0

=== Operating System ===

Windows 6.1.7601.65536
Comment 5 David Naylor 2014-09-03 03:34:01 UTC
Created attachment 7892 [details]
Full example

This example needs a Windows environment, and "nuget restore" should be run after extracting the package (no root directory in zip archive).
Comment 6 David Naylor 2014-09-03 03:37:30 UTC
I have added an attachment to illustrates the issues.  It appears I was wrong on point 6 as Targets does appear to work.  

The full details to reproduce the issues (in turn):

In Project2/Project2.csproj (when compiling using profile Debug|x86):
 1) Remove lines 3-5: Xamarin fails to run Project2.exe in debug mode
 2) Remove line 12: Xamarin fails to run Project2.exe
 3) Remove lines 25-27: Xamarin fails to detect the unit tests
 4) Remove lines 35-37: Xamarin fails to detect the source files (ExampleClass.cs and ExampleClassTest.cs)
In Project1/Project1.csproj (when compiling using profile Coverage|x86):
 5) Remove lines 14-18: Xamarin does not produce a coverage report  for Project1 (empty report)
 1) Xamarin does not appear to properly expand the property in Example.Common.pre.targets:6
 2) Xamarin fails to build the project in the correct location, as specified in Example.Common.pre.targets:5
 3) Xamarin does not detect the NUnit reference, as specified in Example.Common.pre.targets:26-28
 4) Xamarin does not detect the files included in Example.Common.pre.targets:30-34
 5) Xamarin does not use the properties specified in Example.Common.pre.targets:10-14
Comment 7 Lluis Sanchez 2014-09-03 09:20:00 UTC
Custom made csproj files are in general not supported by Xamarin Studio. In may work in some cases, it may not in others, depending on how close the structure is to what Xamarin Studio and Visual Studio expects. There will be some improvements in future releases (since we plan to integrate more deeply with msbuild) but for now we can't support the project structure you are using.

BTW, if you want to share source code files between projects, you can use Shared Projects (http://developer.xamarin.com/guides/cross-platform/application_fundamentals/shared_projects), which are properly supported by Xamarin Studio.