Build error, This project references NuGet

.NetVisual StudioNugetNuget Package-Restore

.Net Problem Overview


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.

.Net Solutions


Solution 1 - .Net

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 2 - .Net

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 3 - .Net

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 4 - .Net

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 - .Net

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.

Solution 6 - .Net

It's a bit old post but I recently ran into this issue. All I did was deleted all the nuget packages from packages folder and restored it. I was able to build the solution successfully. Hopefully helpful to someone.

Solution 7 - .Net

delete this part of code from .csproj file and move to project into a short absolute path. it means, is's better to located on a short absolute path.

C:\Users\name\OneDrive\Desktop\spath1\test\test5....\mvc\Ecommerce

instead of the above, yu can move the project like below,

C:\Users\name\OneDrive\Desktop\mvc\Ecommerce
<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>

Solution 8 - .Net

In my case, I deleted the Previous Project & created a new project with different name, when i was building the Project it shows me the same error.

I just edited the Project Name in csproj file of the Project & it Worked...!

Solution 9 - .Net

I am not so sure, what changes happened on my project, or is this case happened because crash of dll version between vs 2015 or vs 2017 or vs 2019.

I have cloned my project from TFS, and this case happened.

This is what I did :

  • Update Microsoft.Net.Compilers from v.1 to v.1.1
  • Check in Pending changes on Source Control Exproler
  • Undo changes on files : .csproj, packages.config, and web.config
  • Close VS2015 - Clean Solution - Rebuild Solution

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBryanView Question on Stackoverflow
Solution 1 - .NetNatasha VoloshynaView Answer on Stackoverflow
Solution 2 - .NetKevin CandlertView Answer on Stackoverflow
Solution 3 - .NetMatt WardView Answer on Stackoverflow
Solution 4 - .NetJoana BrandãoView Answer on Stackoverflow
Solution 5 - .NetandreyfromnnView Answer on Stackoverflow
Solution 6 - .NetRavimaranView Answer on Stackoverflow
Solution 7 - .NetMafeiView Answer on Stackoverflow
Solution 8 - .NetAdnan HussainView Answer on Stackoverflow
Solution 9 - .NettohaView Answer on Stackoverflow