Bug 34306 - Exit code 127 when building Xamarin CRM app
Summary: Exit code 127 when building Xamarin CRM app
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: NuGet ()
Version: 5.9
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: master
Assignee: Matt Ward
Depends on:
Reported: 2015-09-25 18:10 UTC by Matisse Hack
Modified: 2015-10-05 04:35 UTC (History)
1 user (show)

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

Xamarin Studio Info (1.16 KB, text/plain)
2015-09-28 12:56 UTC, Matisse Hack

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 Matisse Hack 2015-09-25 18:10:31 UTC
When trying to build the Xamarin CRM sample app I get an error that two commands exited with code 127.

1) I clone this repo:


2) And I open app-crm/src/MobileApp/XamarinCRM.sln in Xamarin Studio (version 5.9.7 build 9). The NuGet packages will restore just fine.

3) Now I try building the project and get the following two errors:

/Users/matisseh/xtc/app-crm/src/MobileApp/.nuget/NuGet.targets: Error: Command 'mono --runtime=v4.0.30319 "/Users/matisseh/xtc/app-crm/src/MobileApp/.nuget/NuGet.exe" install "/Users/matisseh/xtc/app-crm/src/MobileApp/XamarinCRM.UITest/packages.config" -source ""   -RequireConsent -solutionDir "/Users/matisseh/xtc/app-crm/src/MobileApp/"' exited with code: 127. (XamarinCRM.UITest)

/Users/matisseh/xtc/app-crm/src/MobileApp/.nuget/NuGet.targets: Error: Command 'mono --runtime=v4.0.30319 "/Users/matisseh/xtc/app-crm/src/MobileApp/.nuget/NuGet.exe" install "/Users/matisseh/xtc/app-crm/src/MobileApp/XamarinCRM/packages.config" -source ""   -RequireConsent -solutionDir "/Users/matisseh/xtc/app-crm/src/MobileApp/"' exited with code: 127. (XamarinCRM)

This seems to be a problem with my install since other people in the office can build this project without issue.

However, I am able to build the project just fine outside Xamarin Studio using xbuild. Also, I am able to run both of the failing commands in command line without any issue.
Comment 1 Matt Ward 2015-09-26 06:23:55 UTC
Can you attach the information from Xamarin Studio - About - Show Details?
Comment 2 Matisse Hack 2015-09-28 12:56:44 UTC
Created attachment 13099 [details]
Xamarin Studio Info
Comment 3 Mark Pevec 2015-10-03 13:32:19 UTC
I encountered this same issue.  To fix I followed the forum (see bottom two posts):

Comment 4 Matt Ward 2015-10-05 04:35:58 UTC
The latest version of the Xamarin CRM application no longer uses a NuGet.targets file so this problem has been resolved.

The 127 error is due to a change in newer versions of Mono, such as version 4.0.4. In order to support El Capitan Mono no longer creates a symlink for mono in /usr/bin. Access to this directory is denied on El Capitan. The symlink is now created in /usr/local/bin. Whilst /usr/local/bin will be on the PATH for the command line it will not be on the PATH for GUI applications, since they have their own PATH environment variable. To see this you can create a console app in Xamarin Studio that outputs the path environment variable.

	class MainClass
		public static void Main (string[] args)
			string variables = Environment.GetEnvironmentVariable ("PATH");
			Console.WriteLine (variables);

If you debug/run this app with Xamarin Studio by default it will run on the external console so you will see the PATH for terminal apps:


If you then go into project options, Run - General and uncheck Run on external console, then debugging this application you will see a different PATH in the Application Output window which does not have /usr/local/bin available:

    /Applications/Xamarin Studio.app/Contents/Resources:/Applications/Xamarin Studio.app/Contents/MacOS:/usr/bin:/bin:/usr/sbin:/sbin

To workaround this problem of Mono no longer being available on the path for GUI apps you can do one of the following:

1) Use the full path to Mono in the NuGet.targets file.
2) Stop using the MSBuild based NuGet package restore.
3) Create a symlink in /usr/bin. On El Capitan you may need to disable System Integrity Protection in order to create this symlink.

Option 1) is probably the simplest. You may need to re-open the solution for Xamarin Studio to pick up the changes. The following is a diff that shows the changes needed in the NuGet.targets file:


The changes are reproduced here:

        <MonoPath Condition="'$(MonoPath)' == '' And Exists('/Library/Frameworks/Mono.framework/Commands/mono')">/Library/Frameworks/Mono.framework/Commands/mono</MonoPath>
        <MonoPath Condition="'$(MonoPath)' == ''">mono</MonoPath>

        <NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">$(MonoPath) --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>

Option 2) would mean the NuGet package restore would now be done by Xamarin Studio on opening the solution. Visual Studio also has its own automatic package restore that is done before the build. To stop using the MSBuild based NuGet package restore you can edit the .csproj file and remove the part that looks like the following:

  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />