Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet package causes trouble in visual studio 2015 and Xamarin

I'm trying to create an android application using Xamarin and Visual Studio 2015 with another friend with source control.

Everything went fine until my friend added a project and he used NuGet packages.

After I activated the get latest version and tried to build the solution I got the error message:

Severity    Code    Description Project File    Line
Error       This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props.    iBuy.API    C:\Users\איציק\Source\Workspaces\iBuy\IBuy\iBuy.API\iBuy.API.csproj 164

I looked up some solutions for this problem and tried to uninstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform and Microsoft.Net.Compilers packages and re installing them but it didn't help. I don't even have a \packages\Microsoft.Net.Compilers.1.0.0\build folder in my solution.

Everything in the NuGet package restore is already checked and I don't have any '.nuget' files in my solution.

What can I do to eliminate that error message?

Thank you in advance!

like image 368
Itzick Binder Avatar asked Sep 19 '15 10:09

Itzick Binder


People also ask

How do I fix a NuGet package error?

Quick solution for Visual Studio usersSelect the Tools > NuGet Package Manager > Package Manager Settings menu command. Set both options under Package Restore. Select OK. Build your project again.

How do I enable NuGet package restore in Visual Studio 2015?

In Tools -> Options -> NuGet Package Manager -> General you need to select the "Allow NuGet to download missing packages" option which allows NuGet to restore and the "Automatically check for missing packages during build in Visual Studio" which enables on build restore.

How do I add a NuGet package to Visual Studio 2015?

From Visual Studio, select Tools > NuGet Package Manager > Package Manager Console. After the Package Manager Console pane opens, verify that the Default project drop-down list shows the project in which you want to install the package. If you have a single project in the solution, it's preselected.

How do I debug NuGet package in Visual Studio?

In order to use Source Code to debug the code form a NuGet package, we need to enable it in Visual Studio. Under the Debug menu, click on Options. First, under General, tick the option to Enable Source Link support. Next, we need to add the NuGet symbol server to the locations where Visual Studio look symbol files.


1 Answers

That error message will be occurring because you do not have the .nuget\NuGet.targets file.

To fix it you could stop using the MSBuild based NuGet package restore or add the .nuget/NuGet.targets file to source control.

The MSBuild based NuGet package restore is deprecated by the NuGet team. It adds some extra elements to your project file (.csproj):

<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>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

You may have more items in the EnsureNuGetPackageBuildImports target element. You can remove these from the project file and instead rely on Visual Studio to restore the NuGet packages.

like image 64
Matt Ward Avatar answered Oct 25 '22 01:10

Matt Ward