Build error, This project references NuGet

159,020

Solution 1

First I would check if your MusicKarma project has Microsoft.Net.Compilers in its packages.config file. If not then you could remove everything to do with that NuGet package from your MusicKarma.csproj.

If you are using the Microsoft.Net.Compilers NuGet package then my guess is that the path is incorrect. Looking at the directory name in the error message I would guess that the MusicKarma solution file (.sln) is in the same directory as the MusicKarma.csproj. If so then the packages directory is probably wrong since by default the packages directory would be inside the solution directory. So I am assuming that your packages directory is:

C:\Users\Bryan\Documents\Visual Studio 2015\Projects\MusicKarma\packages

Whilst your MusicKarma.csproj file is looking for the props file in:

C:\Users\Bryan\Documents\Visual Studio 2015\Projects\packages\Microsoft.Net.Compilers.1.1.1\build

So if that is the case then you can fix the problem by editing the path in your MusicKarma.csproj file or by reinstalling the NuGet package.

Solution 2

Quick solution that worked like a charm for me and others:

If you are using VS 2015+, just remove the following lines from the .csproj file of your project:

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

In VS 2015+ Solution Explorer:

  1. Right-click project name -> Unload Project
  2. Right-click project name -> Edit .csproj
  3. Remove the lines specified above from the file and save
  4. Right-click project name -> Reload Project

Solution 3

This problem appeared for me when I was creating folders in the filesystem (not in my solution) and moved some projects around.

Turns out that the package paths are relative from the csproj files. So I had to change the "HintPath" of my references:

<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
    <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
    <Private>True</Private>
</Reference>

To:

<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
    <HintPath>..\..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
    <Private>True</Private>
</Reference>

Notice the double "..\" in 'HintPath'.

I also had to change my error conditions, for example I had to change:

<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props'))" />

To:

<Error Condition="!Exists('..\..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props'))" />

Again, notice the double "..\".

Solution 4

I also had this error I took this part of code from .csproj 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>

delete that part of code. if you open the file .csproj with notepad, delete the Targuet code, save, and open normaly

Solution 5

Why should you need manipulations with packages.config or .csproj files?
The error explicitly says: Use NuGet Package Restore to download them.
Use it accordingly this instruction: https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore-troubleshooting:

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

Share:
159,020

Related videos on Youtube

Bryan
Author by

Bryan

Updated on July 09, 2022

Comments

  • Bryan
    Bryan almost 2 years

    When I try to build my solution, I get the following error message:

    Severity Code Description Project File Line Suppression State 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.1.1\build\Microsoft.Net.Compilers.props. MusicKarma C:\Users\Bryan\Documents\Visual Studio 2015\Projects\MusicKarma\MusicKarma.csproj 268

    When I look In my packages folder, I can find I file named Microsoft.Net.Compilers.props

    I have tried to use Nuget Restore, but it keeps saying that I have all the packages.

    This happens when I take this project from TFS to one of my computers.

  • katmanco
    katmanco over 7 years
    thanks for the priceless answer , you saved my day :)
  • Oleksandr Skrypnyk
    Oleksandr Skrypnyk over 7 years
    thanks, you helped me a lot, be carefull with path to packages folder
  • Noel Widmer
    Noel Widmer over 6 years
    What do you mean by: I took this part of the .csproj file? Did you delete it?
  • Joana Brandão
    Joana Brandão over 6 years
    No, just delete that part of code. if you open the file .csproj with notepad, delete the Targuet code, save, and open normaly
  • Mawardy
    Mawardy over 5 years
    in my case i changed ..\packages to .\packages and it worked just fine
  • DG7
    DG7 about 5 years
    I saw another answer below that had only the <target> portion removed as I did not have <import> tag section and that worked for me but this answer had instructions for unloading and reloading so that helped a lot. Thanks for sharing @Natasha
  • HaibaraAi
    HaibaraAi about 5 years
    I use this compile success.
  • Jim Speaker
    Jim Speaker almost 5 years
    Removing the above lines from the .csproj disables the ability to Restore Nuget packages.
  • Ashish Kamble
    Ashish Kamble over 3 years
    how to reinstall nuget pacages
  • Roberto Gata
    Roberto Gata over 3 years
    yes, I was similar trouble on VS 2017. I deleted all Import and Error lines with Microsoft.Net.Compilers.1.0.0 value
  • FreeSoftwareServers
    FreeSoftwareServers over 2 years
    I cant believe how far down the thread this is, +1, exactly what I was looking for and would think is the logical step... Worked like a charm! hard to find the restore button visually, it was at the end of the ribbon, maybe a screen show would help?