Build error, This project references NuGet
Asked Answered
B

10

62

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.

Brigidbrigida answered 25/12, 2015 at 18:36 Comment(0)
C
35

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.

Coniferous answered 26/12, 2015 at 12:43 Comment(1)
how to reinstall nuget pacagesTung
H
62

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
Himself answered 9/11, 2018 at 18:30 Comment(4)
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 @NatashaThereabout
I use this compile success.Surfboat
Removing the above lines from the .csproj disables the ability to Restore Nuget packages.Maculation
yes, I was similar trouble on VS 2017. I deleted all Import and Error lines with Microsoft.Net.Compilers.1.0.0 valueAngell
W
44

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 "..\".

Waldron answered 27/1, 2016 at 13:37 Comment(3)
thanks for the priceless answer , you saved my day :)Salerno
thanks, you helped me a lot, be carefull with path to packages folderAndrow
in my case i changed ..\packages to .\packages and it worked just fineEllipticity
C
35

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.

Coniferous answered 26/12, 2015 at 12:43 Comment(1)
how to reinstall nuget pacagesTung
L
14

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

Laconia answered 27/10, 2017 at 10:28 Comment(2)
What do you mean by: I took this part of the .csproj file? Did you delete it?Cummerbund
No, just delete that part of code. if you open the file .csproj with notepad, delete the Targuet code, save, and open normalyStrawser
P
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://learn.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.

Prestidigitation answered 4/7, 2018 at 6:0 Comment(1)
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?Servitor
W
3

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.

Wicker answered 5/6, 2018 at 17:59 Comment(0)
H
2

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, you 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>
Headwork answered 28/3, 2021 at 11:4 Comment(0)
C
0

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

Corissa answered 19/7, 2020 at 13:50 Comment(0)
H
0

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
Habitude answered 5/5, 2021 at 22:33 Comment(0)
W
0

I had the same issue, try these things:

  • Clean the solution and rebuild it
  • if the error appears when trying the step above, check the file names that you're manipulating, to see if they are not following the standards of naming, and try encoding the file names to avoid the error.
William answered 1/7, 2024 at 13:2 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.