Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable Nuget packages restore under Xamarin Studio in Mac OS X

I enabled auto-restore feature for my project under Visual Studio but when I switched to MAC and Xamarin Studio I was unable to restore those packages:

xxx.csproj: Error: This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them

like image 732
Alexey Strakh Avatar asked Apr 12 '14 17:04

Alexey Strakh


People also ask

How do I enable NuGet package restore in Visual Studio?

To do that, go to Tools, NuGet Packaged Manager, then go to Package Manager Settings. Go to the General section, and then make sure you have a checkmark for Allow NuGet to download missing packages and also to automatically check for missing packages during the build in Visual Studio. So click on OK.

How do I force a NuGet package to restore?

Restore by using MSBuild You can use msbuild -t:restore to restore packages in NuGet 4. x+ and MSBuild 15.1+, which are included with Visual Studio 2017 and higher. This command restores packages in projects that use PackageReference for package references.

Does NuGet work on Mac?

NuGet packages contain reusable code that other developers make available to you for use in your projects. See What is NuGet? for background. Packages are installed into a Visual Studio for Mac project using the NuGet Package Manager.

How do I open NuGet Package Manager console in Visual Studio for Mac?

Open your project or solution in Visual Studio, and select Tools > NuGet Package Manager > Package Manager Console to open the Package Manager Console window.


1 Answers

By enabled auto-restore feature I am assuming you are referring to the MSBuild based restore which adds a NuGet.targets file to your project.

That particular error is coming from the MSBuild file:

  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <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>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
  </Target>

The error condition suggests that it cannot find the .nuget\NuGet.targets file. So does this exist? Does the case of the path exactly match?

Also note that there is a problem with the NuGet.targets file on the Mac since it uses a feature of MSBuild which is not supported on Mono. The latest NuGet.targets file available from codeplex may fix this.

It might be easier to remove the MSBuild based package restore and install the NuGet addin for Xamarin Studio, and use the package restore feature from inside Xamarin Studio. To restore from within Xamarin Studio, you can right click the project and select Restore Packages.

like image 113
Matt Ward Avatar answered Sep 19 '22 16:09

Matt Ward