NuGet.targets error installing packages.config using Xamarin Studio on a Mac

faceoffers28faceoffers28 USUniversity ✭✭✭

The Xamarin.Forms project was built in Visual Studio 2013. I am now trying to run the IOs app in Xamarin Studio on a MacBook. I've researched the web and the Forums, but I can't find any articles to assist me in fixing this problem. Here is part of error log.

Building Solution:

Target RestorePackages:
    Executing: mono --runtime=v4.0.30319 "/FILEPATH/.nuget/NuGet.exe" install "/FILEPATH/packages.config" -source ""   -RequireConsent -solutionDir "/FILEPATH/"
    /var/folders/4b/89kb4ktd5n71wsdvkkl7b4wh0000gn/T/tmp7a74846d.tmp: line 1: mono: command not found

/FILEPATH/.nuget/NuGet.targets: error : Command 'mono --runtime=v4.0.30319 "/FILEPATH/.nuget/NuGet.exe" install "/FILEPATH/packages.config" -source "" -RequireConsent -solutionDir "/FILEPATH/"' exited with code: 127.
Task "Exec" execution -- FAILED
Done building target "RestorePackages" in project "/FILEPATH/name.csproj".-- FAILED

Done building project "/FILEPATH/name.csproj".-- FAILED


---------------------- Done ----------------------

Build: 1 errors, 0 warnings

There are 2 of these Build errors, but they are similar, so I'm only including one in this post.

Any help is much appreciated.



  • mattwardmattward GBMember Xamurai

    It looks like something has changed so Xamarin Studio cannot find mono on the path. The same problem was reported on the forum. There is also a bug report which seems to be similar to the forum post but the full build output is not shown so it maybe a different problem, there is no "mono not found" message in the bug report.

    Building from the command line with xbuild works but not when using Xamarin Studio. Using the full path to mono did not seem to fix the problem and the only workaround that worked was to edit the .csproj file to not use the MSBuild based package restore.

    Can you post the versions shown in the about dialog under Show Details? Either here or in the bug report?

  • faceoffers28faceoffers28 USUniversity ✭✭✭

    Here you go.

    === Xamarin Studio ===

    Version 5.9.7 (build 9)
    Installation UUID: 55119d22-166b-4181-a972-6aa5a83445fa
    Mono 4.0.4 ((detached/cb6d6b2)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 400040002

    === Apple Developer Tools ===

    Xcode 7.0 (8227)
    Build 7A220

    === Xamarin.Mac ===

    Version: (Starter Edition)

    === Xamarin.iOS ===

    Version: (Trial Edition)
    Hash: d8e9592
    Branch: master
    Build date: 2015-09-18 23:22:05-0400

    === Xamarin.Android ===

    Version: (Trial Edition)
    Android SDK: /Users/bteague28/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
    4.0.3 (API level 15)
    4.4 (API level 19)
    5.0 (API level 21)
    Java SDK: /usr
    java version "1.7.0_71"
    Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
    Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

    === Xamarin Android Player ===

    Not Installed

    === Build Information ===

    Release ID: 509070009
    Git revision: 31fa64709030b3edb971237780a452a4c69943c4
    Build date: 2015-09-17 11:44:37-04
    Xamarin addins: b105d33d8cd72911ff2cf3ee0b7715d37e5f19a6

    === Operating System ===

    Mac OS X 10.10.5
    Darwin BrianTesMacBook 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64

  • faceoffers28faceoffers28 USUniversity ✭✭✭

    Matt, can you be more specific regarding this comment? "Using the full path to mono did not seem to fix the problem and the only workaround that worked was to edit the .csproj file to not use the MSBuild based package restore."

    Do I edit the .csproj file for the PCL project? How do I tell it not to use the MSBuild based package restore? Is there a yes or no attribute or do I need to comment out a line?


  • faceoffers28faceoffers28 USUniversity ✭✭✭

    I just checked and there are numerous MSBuild references in the .csproj file for the PCL Project.

  • mattwardmattward GBMember Xamurai

    You should be able to fix this by either using the full path to mono in the NuGet.targets file, or by removing the references to the NuGet.targets file in the .csproj files. If you change the path to mono in the NuGet.targets file then you may need to close and re-open the solution for the changes to be picked up by Xamarin Studio. One way to fix this can be found in this commit.

    <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>
  • faceoffers28faceoffers28 USUniversity ✭✭✭
    edited September 2015

    Option 1 fix:

    Matt, what's the default full path to mono on both a MacBook and Windows 10 laptop when installing the Xamarin Platform? I'm asking because I'm running into lots of issues regarding "Nuget package restore" and compatibility between Visual Studio and Xamarin Studio. I've already tried an alternate path on my Mac and that did not work. It would be handy to have the full path to mono as it is written in the code snippet.

    Option 2 fix:

    I see this reference to Nuget in my .csproj file for the IOs project. Is this the only line I need to remove? Should I remove this line from all my .csproj files? Will this cause XS to bypass the Nuget Package Restore method created by Visual Studio?

    <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

    Question? If I remove this line, how will the solution manage Nuget packages? I see a lot of comments online about removing lines items, but nobody ever seems to explain how the solution will work without it. If I remove this line, how does Xamarin Studio manage Nuget packages?

    You mention here that Xamarin Studio as of version 3 can "Automatically restore packages on opening your solution."

    If XS can automatically manage the packages then how can I edit the overall solution to work better with Xamarin Studio while maintaining the .nuget folder and .csproj references required to build the solution in Visual Studio?


  • mattwardmattward GBMember Xamurai

    The full path to mono 4.0.4 on the Mac is shown in the part taken from NuGet.targets file:


    The path to Mono on Windows is not needed since it is not used by the NuGet.targets file.

    I was hoping that using the full path would fix the problem since this is the simplest change to make to get the MSBuild based package restore to work. Unfortunately a change made to Mono to support El Capitan seems to have broken things so assuming that mono is available on the path seems to fail with the NuGet.targets file. I have not had the chance to look into what is going on here. I know that Mono 4.0.4 creates a symlink from /usr/local/bin/mono to the mono inside /Library/Frameworks... instead of /usr/bin/mono which is what Mono used to do.

    If you are removing the NuGet.targets file completely then I would remove the section that looks like the following from the project file:

    <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 The missing file is {0}.</ErrorText>
      <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
    <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

    What the above basically does is run nuget.exe restore when you build the project/solution. This is all done with MSBuild so the Visual Studio nor Xamarin Studio is directly involved. The NuGet team have deprecated this approach for NuGet restore. With Visual Studio 2015 and NuGet 3 they have removed the Enable NuGet Package Restore menu option so you cannot directly set up a NuGet.targets file within Visual Studio 2015, at least not with out manually making the changes to the project files. This Enable NuGet Package Restore menu is still available in Visual Studio 2013.

    You do not need the .nuget/NuGet.targets directory, nor the EnsureNuGetPackageBuildImports target, for Visual Studio or Xamarin Studio. NuGet in Visual Studio has its own automatic package restore that runs before you build. Xamarin Studio's automatic package restore will run when you open the solution, although you can turn this off and run the restore manually from the menu. The only problem it might cause is if you are using a build server. Without the MSBuild based package restore using NuGet.targets you would need to trigger a nuget.exe restore to run before the solution is built. Normally you can add an extra build step to do this.

  • faceoffers28faceoffers28 USUniversity ✭✭✭

    OK, I added the code to the NuGet.targets file in two places and removed the old mono -- runtime NugetCommand Condition.

    <PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
            <!-- We need to launch nuget.exe with the mono command if we're not on windows -->
            <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'">"$(NuGetExePath)"</NuGetCommand>

    mono --runtime=v4.0.30319 "$(NuGetExePath)"

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

    Is this correct?

  • faceoffers28faceoffers28 USUniversity ✭✭✭

    By the way, I'm not sure if that truly fixed the problem, but now there are two new errors. I'm not sure if they were already there or created by the Nuget.targets file change I just made. Here they are. Both errors are located in the Xamarin.IOs.Common.Targets file.

    Error 1
    Could not locate the IOs 9 SDK usr path at /Applications/

    Error 2
    Error Executing task DetectSdklocations: Argument can not be null. Parameter name: Path 1

    The interesting thing is that I had to downgrade to Xamarin.iOS 8.10 because the iOS Project uses that version. iOS version 9 was the previous version. Does this have anything to do with that?


  • mattwardmattward GBMember Xamurai

    The NuGet.targets change looks good to me. This should fix the 127 error which it looks like it has. The other errors seem to different to the NuGet.targets problem.

    Not sure about the iOS error. It looks like the project is being compiled for iOS 9 but that SDK is not installed.

  • faceoffers28faceoffers28 USUniversity ✭✭✭

    I created a separate discussion for the iOS 9 SDK issue since it doesn't sound like it was caused by the fix provided in this discussion. The new discussion can be found here.

  • JimBordenJimBorden USMember ✭✭

    Why is this hack necessary? mono is in my path, but Xamarin Studio is schizo or something because it still says it cannot find it. Same with xbuild.

  • JimBordenJimBorden USMember ✭✭
    edited October 2015

    After figuring out how to disable SIP, I created symlinks in /usr/bin and Xamarin Studio started working again. Obviously, it is getting its search path from SOMEWHERE. The question is WHERE? At the basic level, the contents of my /etc/paths file includes /usr/local/bin. When I launch sh the path shows a containing /usr/local/bin

    Could Xamarin Studio be using a hardcoded path for searching within the MSBuild "Exec" command?

    EDIT It looks like the path getting set for msbuild is


    Does this look familiar?

  • MikeGarnerMikeGarner USMember

    I am also having this issue. Can you post your fixed NuGet.targets file please?

  • mattwardmattward GBMember Xamurai

    @MikeGarner - The change to the NuGet.targets file is shown in the comment above.

  • MikeGarnerMikeGarner USMember

    @mattward - I tried that and still got the 127 error, so was hoping that you could post a copy of a working version in case I have done it incorrectly!

  • mattwardmattward GBMember Xamurai

    @MikeGarner - The attached file works for me on Yosemite. I had to rename it to be .txt since the forum does not seem to like .targets.

    Can you post the error message if it still does not work?

  • MikeGarnerMikeGarner USMember

    @mattward - That is working for me now. Thank you very much for your help.

  • Worked for me, too. Thank you.

Sign In or Register to comment.