Reputation: 3541
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.
Upvotes: 62
Views: 250325
Reputation: 41
I had the same issue, try these things:
Upvotes: 0
Reputation: 3819
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>
Upvotes: 2
Reputation: 5507
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 :
Upvotes: 0
Reputation: 181
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
Upvotes: 15
Reputation: 1
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...!
Upvotes: 0
Reputation: 797
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:
Upvotes: 66
Reputation: 601
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 "..\".
Upvotes: 46
Reputation: 111
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.
Upvotes: 6
Reputation: 441
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.
Upvotes: 4
Reputation: 47987
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.
Upvotes: 35