Bug 55470 - Building from command line crashes
Summary: Building from command line crashes
Status: RESOLVED ANSWERED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: General ()
Version: 4.3.0 (C9)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-04-21 14:24 UTC by Alexandre Pepin
Modified: 2017-06-21 17:35 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: Yes
Last known good build: XamarinVS 3.11.1594.0 (a06d6d5)


Attachments
App1 (28.18 KB, application/zip)
2017-04-21 14:25 UTC, Alexandre Pepin
Details
EventViewerLog (3.79 KB, text/plain)
2017-04-21 14:26 UTC, Alexandre Pepin
Details
Complete use case (6.93 MB, application/zip)
2017-04-26 16:53 UTC, Alexandre Pepin
Details
Test case from Comment 6 with .vdproj, cleaned (26.42 KB, application/zip)
2017-04-26 19:26 UTC, Brendan Zagaeski (Xamarin Team, assistant)
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 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 ANSWERED

Description Alexandre Pepin 2017-04-21 14:24:58 UTC
# Steps to reproduce
Execute the following command with the good paths in command prompt in Administrator mode:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.com" "C:\Projects\App1\App1.sln" /Build Debug
I've attached the project.

# Expected behavior
To build my iOS App1

# Actual behavior
It crashes.
If I try the same command but with a solution that doesn't contain an iOS project, it builds without problems

# Supplemental info (logs, images, videos)
I've attached the log in that I got from the Event view of Windows

# Test environment (full version information)
Microsoft Visual Studio Professional 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01055

Installed Version: Professional

Visual Basic 2015   00322-40000-00000-AA258
Microsoft Visual Basic 2015

Visual C# 2015   00322-40000-00000-AA258
Microsoft Visual C# 2015

Visual C++ 2015   00322-40000-00000-AA258
Microsoft Visual C++ 2015

Windows Phone SDK 8.0 - ENU   00322-40000-00000-AA258
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   7.18.00214.2
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015.1   14.1.20810.0
ASP.NET and Web Tools 2015.1

ASP.NET Web Frameworks and Tools 2012.2   4.1.41102.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.40314.0
For additional information, visit http://www.asp.net/

Azure App Service Tools v2.8.1   14.0.11123.0
Azure App Service Tools v2.8.1

Common Azure Tools   1.8
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

File Nesting   2.6.67
Automatically nest files based on file name and enables developers to nest and unnest any file manually

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

JustDecompile Tools   1.0
Makes JustDecompile functionality available in VIsual Studio. Requires JustDecompile installation.

Merq   1.1.14-alpha (21c13c9)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft .NET Core Tools (Preview 2)   14.1.20810.0
Microsoft .NET Core Tools (Preview 2)

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

Mono Debugging for Visual Studio   Mono.Debugging.VisualStudio
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   3.5.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PoxAutoRun   1.0
PoxAutoRun Visual Studio Package Detailed Info

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   14.0.60519.0
Microsoft SQL Server Data Tools

tangible T4 Editor   2.3.0
tangible engineering GmbH

TypeScript   1.8.36.0
TypeScript tools for Visual Studio

Web Compiler   1.11.326
Compiler for LESS, Sass and CoffeeScript files

Web Essentials 2015.3   3.0.235
Adds many useful features to Visual Studio for web developers. Requires Visual Studio 2015

Xamarin   4.3.0.789 (4d2ed3d)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   7.1.0.43 (3a62f1e)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS   10.4.0.128 (ba11e48)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 1 Alexandre Pepin 2017-04-21 14:25:57 UTC
Created attachment 21699 [details]
App1
Comment 2 Alexandre Pepin 2017-04-21 14:26:46 UTC
Created attachment 21700 [details]
EventViewerLog
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-21 20:25:34 UTC
Non-engineering team preliminary quick review




## Suspected to be a regression or a problem with a new feature?

Possibly.  @Alexandre, did this issue appear for you after a Xamarin update?  Or is this the first time you've tried building from the command line?  Or do you have any other hunches about what might have changed between when this was working and when it stopped working?




## Specific to one particular project, development computer, or target mobile device?

Unfortunately, this seems to be particular to some details about the development environment on the reporter's computers.  I tried to replicate the behavior on my computers by running a command similar to the following:

msbuild /t:Build /p:ServerAddress=192.168.2.1 /p:ServerUser=macuser /p:ServerPassword=mypassword /p:Configuration="Debug" /p:Platform="iPhone" App1.sln

The build completed successfully, and there were no crashes.  I tried this both when Visual Studio was closed and when Visual Studio was running and connected to the Mac.  I also tried building with `/p:Platform="iPhoneSimulator"`, and that was also successful.  (See the testing environment details below.)




## Considers the relevant log files for the part(s) of the process where something goes wrong (IDE editing, MSBuild building, deploying, launching, attaching the debugger, an in-app error, or something else) and has them attached?

Yes, the report includes a good log for the crash itself.  Since this problem happens during a build, there's a chance it might be useful to collect the diagnostic build output as well.


@Alexandre, when you get a chance, you can try the following steps to be thorough:

1. Run the "bad" command line build once more with diagnostic verbosity, using a command similar to the following (after replacing the ServerAddress, ServerUser, and ServerPassword as needed):

   msbuild /t:Build /p:ServerAddress=192.168.2.1 /p:ServerUser=macuser /p:ServerPassword=mypassword /p:Configuration="Debug" /p:Platform="iPhone" /v:diagnostic App1.sln > "%USERPROFILE%\Desktop\DiagnosticOutputBug55470.txt"

2. Zip up and attach back the "DiagnosticOutputBug55470.txt" file from your Desktop.


Thanks!




## Already took up time for many users?

It seems this is a fairly uncommon problem so far.  There is one similar report on the forums [1] from back in August 2016, but no other exact matches on Bugzilla, the Xamarin forums, or Stack Overflow.

[1] https://forums.xamarin.com/discussion/73709/visual-studio-2015-xamarin-command-line-crash


(Note to the Xamarin team: It seems the `ToolbarIconChanger.FindButtonAsync()` method has come up at least once before in non-public Bug 40093, which was an old issue in XamarinVS 4.1 ("Cycle 7").  Perhaps there is a related edge case that can still affect recent versions?)




## Makes development (a) difficult, impossible, or potentially hazardous, (b) moderately inconvenient, or (c) mildly inconvenient for users?

(b) or perhaps (a), depending on whether the reporter is currently able to move forward with some development work by building within the IDE.




## My testing environment info (brief)



### Windows

XamarinVS 4.3.0.789 (4d2ed3d)

Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01586

Windows 10 (64-bit) Version 1607 (OS Build 14393.1066)
US English locale, US Eastern time zone



### Mac
Xamarin.iOS 10.4.0.128 (cycle9: ba11e48)
Mono 4.8.0 (mono-4.8.0-branch/8f6d0f6)
Xcode 8.2.1, Build version 8C1002
Mac OS 10.12.4
Comment 5 Alexandre Pepin 2017-04-26 16:52:41 UTC
I created a more complete use case of my problem in the attached solution

The solution contains 4 projects inside:
- A WPF application (WpfApplication1)
- An iOS application (App1)
- A portable class library that shares code between the WPF application and the iOS application
- An installer project (Setup1.vdproj) that creates an MSI to install the WPF application

To load the installer project in Visual Studio, you need to install the following extension: https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.MicrosoftVisualStudio2015InstallerProjects

We also have TeamCity for our CI that builds our solution and generates the artifacts to release in production. TeamCity can't build the installer project with msbuild. It gives the following warning: 

"warning MSB4078: The project file "Setup1.vdproj" is not supported by MSBuild and cannot be built."

An easy solution to this is to build the vdproj with devenv instead of msbuild. So if I try the following command: 

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.com" "C:\Projects\App1\Setup1\Setup1.vdproj" /Build Debug

It crashes like I reported initially. If you remove the App1 from the solution and retry the command, it builds the vdproj without any error

To anwser your questions

- Did this issue appear for you after a Xamarin update?
No, it appears because we added a vdproj to our solution and we are trying to make it build with TeamCity

- Is this the first time you've tried building from the command line
Yes for the vdproj. TeamCity is building our iOS projects without any problem using msbuild

- Do you have any other hunches about what might have changed between when this was working and when it stopped working
We added a vdproj to our solution and TeamCity can't build it using msbuild. Using devenv should work but crashes

- When you get a chance, you can try the following steps to be thorough
Your command works with msbuild, but I really need to build the vdproj using devenv and not msbuild

Our CI is now blocked because of this problem
Comment 6 Alexandre Pepin 2017-04-26 16:53:22 UTC
Created attachment 21812 [details]
Complete use case
Comment 7 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-26 19:26:01 UTC
Created attachment 21824 [details]
Test case from Comment 6 with .vdproj, cleaned

Many thanks for the clarification on the intended use scenario and the motivation for using `devenv.com` as the build command (as you mentioned in Comment 0).  I was able to replicate the problem with the original test case from Comment 1 once I re-attempted the test using the `devenv.exe` command as described in Comment 0, but I think the test scenario described in Comment 5 is even better.




## Steps followed to test


1. Unzip the attached test case. (This is the same test case from Comment 6 trimmed down to remove the bin\ and obj\ directories.)


2. Install the "Installer Projects" extension

VS 2015: https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.MicrosoftVisualStudio2015InstallerProjects
VS 2017: https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.MicrosoftVisualStudio2017InstallerProjects


3. Open a "Developer Command Prompt for VS 2015" window from the Windows Start/Cortana menu.


4. Attempt to build _just_ the "Setup1.vdproj" project on the command line using `devenv`:
devenv App1.sln /Build "Debug" /Project "Setup1"
(https://blogs.msdn.microsoft.com/aaronhallberg/2007/06/29/building-from-the-command-line-with-devenv/)


5. Wait for the command to finish.


6. Open the Event Viewer and look under "Windows Logs > Application".




## Actual Results

The Event Viewer shows that `devenv` crashed in a call to `ToolbarIconChanger.FindButtonAsync()`.  Perhaps there is some UI initialization code that the Xamarin extension for VS tries to run in this scenario that is not appropriate when `devenv` is executed without the GUI?

> Application: devenv.exe
> Framework Version: v4.0.30319
> Description: The process was terminated due to an unhandled exception.
> Exception Info: System.AccessViolationException
>    at Microsoft.Internal.VisualStudio.Shell.Interop.IVsCommandBarsCustomizerPrivate.GetCommandBars(Microsoft.Internal.VisualStudio.Shell.Interop.IVsCommandBarCustomizerCollectionPrivate ByRef)
>    at Microsoft.VisualStudio.PlatformUI.Automation.CommandBarCustomizationService.get_CommandBars()
>    at Microsoft.VisualStudio.PlatformUI.Automation.CommandBars.get_Count()
>    at Microsoft.VisualStudio.PlatformUI.Automation.CommandBars.<GetEnumerator>b__65_0()
>    at Microsoft.VisualStudio.Shell.ThreadHelper.Invoke[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Func`1<Int32>)
>    at Microsoft.VisualStudio.PlatformUI.Automation.CommandBars+<GetEnumerator>d__65.MoveNext()
>    at System.Linq.Enumerable+<CastIterator>d__94`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
>    at System.Linq.Enumerable.FirstOrDefault[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>, System.Func`2<System.__Canon,Boolean>)
>    at Xamarin.VisualStudio.Remote.ToolbarIconChanger+<FindButtonAsync>d__4.MoveNext()



## Workaround and Expected Results

Part of the complication is that the `devenv /Build` command itself isn't too sophisticated.  It tries to load things for the Xamarin.iOS project even when you explicitly specify that you only want to build `/Project "Setup1"` (even though Setup1 has no dependencies on the iOS app project).

One way work around this issue is to make a second copy of the .sln file that is dedicated to command line builds of the Setup1 project.  Once you have removed the iOS app project from the new .sln file via the Visual Studio IDE, the `devenv /Build` command runs to completion without crashing:

> 1>------ Build started: Project: Models, Configuration: Debug Any CPU ------
> 1>  Models -> C:\source\App1\Models\bin\Debug\Models.dll
> 2>------ Build started: Project: WpfApplication1, Configuration: Debug Any CPU ------
> 2>  WpfApplication1 -> C:\source\App1\WpfApplication1\bin\Debug\WpfApplication1.exe
> ------ Starting pre-build validation for project 'Setup1' ------ 
> ------ Starting pre-build validation for project 'Setup1' ------ 
> ERROR: An error occurred while validating.  HRESULT = '8000000A'
> ERROR: An error occurred while validating.  HRESULT = '8000000A'
> ------ Pre-build validation for project 'Setup1' completed ------
> ------ Pre-build validation for project 'Setup1' completed ------
> 3>------ Build started: Project: Setup1, Configuration: Debug ------
> 3>------ Build started: Project: Setup1, Configuration: Debug ------
> ========== Build: 2 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
(I'm not sure why the Setup1 project fails to build from the command line in my environment, but it works from the IDE for me, and presumably it works for the reporter of the bug in their CI builds, so the "1 failed" message is ignorable for the purposes of this bug.)




## Confirmation status: confirmed

It seems like historically this scenario might not have ever been an explicit part of Xamarin's compatibility test matrix, but something did change in XamarinVS 4.0 (Cycle 6) with the introduction of SSH connection to the remote Mac that apparently causes the Xamarin VS extension to call into the problematic `ToolbarIconChanger.FindButtonAsync()` when `devenv` is invoked without a GUI.

> Crash:    XamarinVS 4.5.0.387   (1585aad) + Visual Studio 2017 Preview 15.2 (26419.1-Preview)
> Crash:    XamarinVS 4.4.0.34    (3f99c5a) + Visual Studio 2017 15.1 (26403.7)
> Crash:    XamarinVS 4.3.0.789   (4d2ed3d) + Visual Studio 2015 Update 3
> Crash:    XamarinVS 4.0.0.1689  (f860fe4) + Visual Studio 2015 Update 3
> NO Crash: XamarinVS 3.11.1594.0 (a06d6d5) + Visual Studio 2015 Update 3
(Note to the Xamarin team: the crash seems to happen before any attempt to connect to the Mac remotely, so the version information for the Mac is not relevant. For what it's worth, the iOS app project can even be built successfully via `devenv /Build` on XamarinVS 3.11 + Xamarin.iOS 9.1.)
Comment 8 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-26 19:35:35 UTC
## Bug severity adjustment

I will tentatively adjust the severity of this bug down to "Normal" for now based on the possible workaround of creating a second .sln file that omits Xamarin.iOS projects for use in CI builds of .vdproj projects.  But Alexandre let me know if I'm overlooking a detail about how that workaround would not be applicable to your real solution.  Thanks!
Comment 9 Jose Gallardo 2017-06-21 17:35:16 UTC
Hi,

Our command-line CI support is MSBuild based. On that scenario, what you can use is a WIX project to get an installer for the WPF application.

Otherwise, you can go ahead with the approach suggested by Brendan.

Thanks for reporting