Bug 55147 - "Content" Build Action does not copy file into .app bundle when project is built with `msbuild` rather than `xbuild`
Summary: "Content" Build Action does not copy file into .app bundle when project is bu...
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: MSBuild ()
Version: 3.4.0 (15.2)
Hardware: PC Mac OS
: High normal
Target Milestone: 15.4
Assignee: Bugzilla
: 54662 57029 57812 ()
Depends on:
Reported: 2017-04-13 12:34 UTC by David Lilley
Modified: 2017-09-05 12:17 UTC (History)
11 users (show)

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

Self Contained Test (352.21 KB, application/zip)
2017-04-13 12:34 UTC, David Lilley
Diagnostic build outputs from `msbuild` and `xbuild` for comparison (84.00 KB, application/zip)
2017-04-13 16:01 UTC, Brendan Zagaeski (Xamarin Team, assistant)

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 Lilley 2017-04-13 12:34:11 UTC
Created attachment 21506 [details]
Self Contained Test

Using Visual Studio for Mac and Project containing a file.( Content.txt)  The File is set to Build Action Content and should be copied to the resources folder.

On Xamarin Studio this works.

Attached Test

=== Visual Studio for Mac Preview ===

Version Preview 6 (7.0 build 2740)
Installation UUID: eb84151c-06d1-4fb8-9a53-a5ebe900626c
	Mono (2017-02/851b6c7) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 500000048

=== .NET Core ===

Runtime: Not installed
SDK: Not installed
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.0.0/lib/mono/msbuild/15.0/bin/Sdks

=== NuGet ===


=== Xamarin.Profiler ===

Version: 1.5.2
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.3 (12169)
Build 8E162

=== Xamarin.iOS ===

Version: (Visual Studio Enterprise)
Hash: 6bea7a5b
Branch: d15-2
Build date: 2017-04-10 17:23:46-0400

=== Xamarin.Android ===

Version: (Visual Studio Enterprise)
Android SDK: /Users/davidlilley/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		6.0   (API level 23)
		7.1   (API level 25)

SDK Tools Version: 25.2.3
SDK Platform Tools Version: 25.0.1
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:

=== Xamarin.Mac ===

Version: (Visual Studio Enterprise)

=== Xamarin Inspector ===

Version: 1.2.1
Hash: 0ea0a12
Branch: d15-1
Build date: Thu, 06 Apr 2017 20:24:44 GMT

=== Build Information ===

Release ID: 700002740
Git revision: 43886850206b214855338d0de1256f2bfedf5763
Build date: 2017-04-09 11:44:06-04
Xamarin addins: 2a9cb93dc912f67727067a5f638c5eb6b9e5fc61
Build lane: monodevelop-lion-d15-2

=== Operating System ===

Mac OS X 10.12.4
Darwin Davids-iMac.local 16.5.0 Darwin Kernel Version 16.5.0
    Fri Mar  3 16:52:33 PST 2017
    root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
Comment 1 David Lilley 2017-04-13 12:46:08 UTC
The Self contained Test

On Visual Studio it will throw FileNotFoundException but the expected result should show a AlertView with "Some Random Content" text.
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-13 15:56:25 UTC
## Note to the Xamarin team

I will temporarily assign this bug to the Xamarin.Mac product for a first quick look about whether this is an issue where Xamarin.Mac will need to be adjusted to match up with `msbuild` or whether it is a bug in `msbuild`.  Thanks!

## Steps tested

1. Build and run the attached test case in the Debug configuration.

2. Click the "Press Me" button.

## Preliminary confirmation status: confirmed difference in behavior between `msbuild` and `xbuild` when building a Xamarin.Mac project

### BAD result with "Visual Studio > Preferences > Build > Build with MSBuild instead of xbuild" _enabled_

> System.IO.FileNotFoundException: /Users/Shared/Projects/ExternalLibraryFile/ExternalLibraryFile/bin/Debug/ExternalLibraryFile.app/Contents/Resources/Content.txt

### GOOD result with "Build with MSBuild" _disabled_

An alert dialog is displayed in the application:

> Test
> Sample Content Hurrah.
> [OK]
(After changing the "Build with MSBuild" setting, I quit and reopened Visual Studio for Mac Preview and then rebuilt the solution and reran the ExternalLibraryFile app.)

### BAD result with `msbuild` on the command line

$ msbuild /t:Build ExternalLibraryFile.sln

The directory "ExternalLibraryFile/bin/Debug/ExternalLibraryFile.app/Contents/Resources/" does NOT contain Content.txt:

> $ ls ExternalLibraryFile/bin/Debug/ExternalLibraryFile.app/Contents/Resources/Content.txt
> ls: ExternalLibraryFile/bin/Debug/ExternalLibraryFile.app/Contents/Resources/Content.txt: No such file or directory

### GOOD result with `xbuild` on the command line

$ xbuild /p:Configuration=Debug /t:Build ExternalLibraryFile.sln

The directory "ExternalLibraryFile/bin/Debug/ExternalLibraryFile.app/Contents/Resources/" DOES contain Content.txt:

> $ ls ExternalLibraryFile/bin/Debug/ExternalLibraryFile.app/Contents/Resources/Content.txt
> ExternalLibraryFile/bin/Debug/ExternalLibraryFile.app/Contents/Resources/Content.txt

## Testing environment info (brief)

Mono (2017-02/851b6c7)

Xcode 8.3 (12169), Build 8E162
Mac OS 10.12.4
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-13 16:01:30 UTC
Created attachment 21518 [details]
Diagnostic build outputs from `msbuild` and `xbuild` for comparison
Comment 4 David Lilley 2017-06-07 13:54:55 UTC
Hi all,

Any movement on this, I would love to switch to visual studio for mac, but this issue is kind of stopping from migrating. Still stuck with Xamarin Studio which has other annoying issues editing issues using {}

I take it that Xamarin Studio is not being further developed and we should move to Visual Studio ?
Comment 5 Chris Hamons 2017-06-07 17:00:32 UTC
You can use VSfM with xbuild. There is a setting (VS -> Preferences -> Projects -> Builds -> Build with MSBuild instead of xbuild).

It is suggested that XS users migrate to VSfM as that is where future development will occur (you can think of it as the newest version of XS with additional features).
Comment 6 Jeffrey Stedfast 2017-06-07 17:12:01 UTC
Use 'BundleResource', not 'Content'. We've been telling people not to use 'Content' since 2011.

I don't know when, why, or how this broke... but you shouldn't be using Content regardless.
Comment 7 Chris Hamons 2017-06-07 17:30:07 UTC
In that case, I filed this bug to suggest we need a warning in msbuild to use BundleResource instead.
Comment 8 David Lilley 2017-06-08 08:29:18 UTC
Thanks all, switched to VSfm and happily building. with Bundle Resource and xBuild

Just to confirm my findings

Using BundleResource: 

MSBuild Bad Result
xbuild Good Result

Using Content: 

MSBuild Bad Result
xbuild Good Result
Comment 9 Jeffrey Stedfast 2017-06-08 14:37:21 UTC
BundleResource works with both xbuild and msbuild.
Comment 10 David Lilley 2017-06-08 14:49:56 UTC

Just rechecked with sample above. Changed the file Content.txt to BundleResource

Checked the option  Build with MSBuild
Deleted all bin and obj files in both projects.
Restarted VSfM 
Checked settings
Compiled and Ran and recieved a FileNotFoundException.
Comment 11 Chris Hamons 2017-06-08 16:43:45 UTC
I can confirm, BundleResources is not doing the expected action in this use case.
Comment 12 Jeffrey Stedfast 2017-06-08 18:09:35 UTC
Comment 13 Jeffrey Stedfast 2017-06-08 18:16:25 UTC
For whatever reason, the Mac targets did not copy my iOS targets.

That patch should fix things.
Comment 14 Jeffrey Stedfast 2017-06-09 14:49:08 UTC
*** Bug 57029 has been marked as a duplicate of this bug. ***
Comment 15 Jeffrey Stedfast 2017-06-09 18:58:40 UTC
*** Bug 54662 has been marked as a duplicate of this bug. ***
Comment 16 GouriKumari 2017-06-14 21:52:50 UTC
Verification Steps:

##Good Result

Verified with XM master build (master: 9accdb38) and the issue is fixed.

## Logs:
Build Log: https://gist.github.com/GouriKumari/e6954a7e30569fbaf947961892ca0e0e
Screenshot: https://screencast.com/t/oUPFLqQg4Bk

## Bad Result:
Reproduced with XM d15-3 build

## Logs:
Build Log: https://gist.github.com/GouriKumari/68ce2f61dd75b0e5c91d117663fec2a4
Screenshot: https://screencast.com/t/34cZgK8o

Marking this bug as resolved fixed.
Comment 18 xamarin-release-manager 2017-07-12 13:09:36 UTC
Fixed in version (d15-3)

Author: Jeffrey Stedfast
Commit: 367da32fcb3fc47c9247c72a3e17cf924d085887 (xamarin/xamarin-macios)
Comment 19 Chris Hamons 2017-07-31 18:24:19 UTC
*** Bug 57812 has been marked as a duplicate of this bug. ***
Comment 20 Neeraj Deshmukh 2017-09-05 12:17:04 UTC
Verified on Visual Studio Enterprise 2017 for Mac (Preview).

#Build info: 


#Steps tested
1. Build and run the attached test case in the Debug configuration.
2. Click the "Press Me" button.
#IDE Logs attached.

Hence moving card into QA Accepted on release branch.