Error using nuget in VS2012 "missing packages" - visual-studio

When I build my project from within VS2012 I get the following error message
This project references NuGet package(s) that are missing on this computer.
Enable NuGet Package Restore to download them.
I have the nuget options set for NuGet to download missing packages.
Yet I still get the error.
I have nugget 2.7 installed. With VS2012 update 3

Please follow below mentioned steps:
Step 1:
Please enable Nuget Package Restore by right clicking on solution [as mentioned in below screenshot]
Step 2: [Follow this if the issue / error is not resolved by following step 1]
Still if you face the issue, please open .csproj file in notepad and check for the package path which might look like
So your solutions directory structure will be like:
\SolutionDirectory\
Package Directory:
\SolutionDirectory\packages
Project Directory:
\SolutionDirectory\ProjectName\ProjectName.csproj
Please open this .csproj [in which you're getting error] in notepad and search for packages path and update it to its relevant path.
For e.g. my .csproj contained, if .csproj file contains ..\..\packages then update that path with ..\packages

As Dan was alluding to, if your solution has a .nuget folder (from enabling package restore), then nuget 2.7's automatic package restore feature is disabled, as per http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore.
If automatic package restore is disabled, then any package that installs a project target files will cause your build to fail until you manually restore that package in your solution, as described by http://blogs.msdn.com/b/dotnet/archive/2013/06/12/nuget-package-restore-issues.aspx. (Note that the workarounds described in the link are out-dated now that nuget 2.7 automatic package restore is available.)
So, if both these things are true, then delete the NuGet.targets file in the .nuget folder, and Nuget will then restore the missing package before invoking MSBuild. You can delete nuget.exe in the .nuget folder as well, as it will no longer be used.

The answers are very helpful for me to find the solution. Since the resolution to my specific issue requires one more step, I report it here in case it is helpful to others.
The error I was getting:
Error 117 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 ..\..\Windows Phone 8\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets.
I followed the answers and deleted all the suggested things, but the error still kept showing up. I finally got rid of it by deleting the following line in the .csproj:
<Error Condition="!Exists(...

Delete NuGet
Remove with Notepad .targets that depending NuGet from project file
Install latest version of NuGet
Restart Visual Studio and reopen project/solution.
If you want you can add new .nuget files with latest version of NuGet

Open csproj file in notepad and remove Error Condition elements from here (or make these conditions work):
<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'))" />
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.101.0\build\net45\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.101.0\build\net45\System.Data.SQLite.Core.targets'))" />
</Target>

Remove the .nuget directory from the solution if it exists. Edit the project file and remove the elements Import and Target that contain references to the .nuget folder, Save and reload the project.

try this,
List item
right click on the solution
click manage NuGet
click setting on the left bottom corner
check the Allow NuGet to download missing package.

Simply Right Click on Solution and "Enable NuGet Package Restore" solve my problem.

Related

Is NuGet automatic package restore in Visual Studio 2015 a fairy tale/mythical beast?

I have been trying to figure out why automatic package restore in Visual Studio 2015 doesn't work.
As I understand it there is nothing to do but check a couple of settings. When you build, it looks for missing packages and downloads them automatically.
I have a solution that has 15 individual projects. The majority of them will not compile because of "missing packages".
I do not have any of the legacy NuGet (.nuget folder etc.) in any of these projects and I have the latest and greatest version of NuGet.
Visual Studio simply will not download the missing files. I deleted the solution package folder and it does re-create and download all of the packages when I build, but each individual project still shows missing references.
If I go to the package manager console and issue a
Update-Package -reinstall
then the packages download and everything works. I'm just wonder why it doesn't do this automatically.
It's supposed to right?
NuGet Restore only restores files in the packages directory, but does not restore files inside your project or modify your project.
For example, if there has a package will add some reference dlls or add some content files into your project. After deleting these reference dlls and content files from your project, it will not be added when restoring this package. This will cause the your project could not find the missing pacakges when compile.
So we need use "Update-Package -reinstall" command to force reinstall the package references and content files into project.
Update the example for sharing projects in a team:
Following is my solution structure, the CommDLL project installed some NuGet packages and entire solution is managed by a source control.
I download this solution on another machine from source control use another user account and install another NuGet packages into the CommDLL project. Then use some content from the new installed package and build the project successful. Please make sure the package dlls has been added into your project and it has been set the correct HintPath in .csproj file.
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
Next, I check in this modified project into the source control. Please make sure you the .csproj file and packages.config file are checked in.
Now I get the latest version on another machine to get the modified content. After check out the latest version from source control, the package references are shown with a warning because the project is not compiled, which means the packages are not restored. Please rebuild this project, it will restore the packages for your project (make sure your Visual Studio 2015 has enable "Allow NuGet to download missing packages" and "Automatically check for missing packages during build in Visual Studio" before rebuild this project).

Visual Studio 2015 can't find nuget package references and DLLs in packages folder

I've been given a C# project by someone else. I opened the project and tried to install all the Nuget packages by doing a Update-Package -reinstall.
It downloaded all the packages in the packages folder.
/Projects
/WebApiTest (root folder)
WebApiTest.csproj
WebApiTest.sln
/packages (packages are loaded in this folder)
But the entire project still says that it's missing all the references. I editted the csproj file to see where it tries to load the packages from, and that is:
<ItemGroup>
<Reference Include="Antlr3.Runtime">
<HintPath>packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll</HintPath>
</Reference>
<Reference Include="EntityFramework">
<HintPath>packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer">
<HintPath>packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
... etc.
So I assume it starts looking in the same directory as the csproj file is in. In that same directory is also the packages folder that has all the DLL files. So the path seems to be right.
Why is my project still not able to load the references?
This post is starting to get old, but as I have encountered this issue myself and fixed it, I'll share a possible solution.
I had to manually uninstall and re-install the packages by right-clicking on the problematic project, Manage NuGet packages..., then uninstall/reinstall from there.
Be careful on the packages version: be sure to grab the same, in case the project isn't using the latest.
A noticeable effect for me after this procedure is that the paths in the csproj file got updated.
Hope it'll help someone :)
Open up the csproj file for your project in a plain text editor and fix the paths for the DLL's. You may see something like:
<HintPath>packages\etc\etc\etc...</HintPath>
I changed those occurrences to:
<HintPath>..\packages\etc\etc\etc...</HintPath>
I pushed this change from the computer that the project was working fine on and pulled them back down on the bad machine and it was no longer an issue.
Note: This wouldn't be an issue if your project file was in the same folder as your packages folder.
Does NuGet successfully restore the packages from the command line?
Try running this from the command line, from the same folder as your solution:
nuget restore WebApiTest.sln
Note, you may need to fully qualify the execution of nuget (e.g. C:\nuget\nuget.exe), or have it in your path.
You may need to download the NuGet executable, if you haven't already.
If that doesn't work, hopefully it will shed some light on why!
What fixed the missing project references for me was to simply:
Close Visual Studio
Delete the "packages" folder where all the nuget packages are stored (probably at your solution-level or else project-level directory)
Open the solution again in Visual Studio
If you have automatic package restore on, just rebuild, else first restore the nuget packages (from the solution context menu) and then rebuild.

NuGet restore enabled but I still get an error

Why do I get the following build output error when I already have NuGet package restore enabled?
Restoring NuGet packages...
To prevent NuGet from downloading packages during build, open the
Visual Studio Options dialog, click on the Package Manager node and
uncheck 'Allow NuGet to download missing packages'.
All packages listed in packages.config are already installed.
MyProject.csproj: error : This project references NuGet package(s)
that are missing on this computer. Enable NuGet Package Restore to
download them.
It only happens on one project.
I am using Visual Studio 2013 and NuGet 2.8.
Make sure to upgrade to the latest version of NuGet which does package restore automatically. See this post by David Ebbo for more information: http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html
You're going to want to delete the NuGet targets (delete the .nuget folder and then manually edit your .csproj files and remove the lines that import the NuGet.targets file). This is no longer needed. When you compile your solution, NuGet will restore it.

NuGet not restoring packages on build

I have just created a workspace on a new machine, got latest of our project from TFS, enabled NuGet Restore, and I get the following (skimmed-down) output:
1>------ Rebuild All started: Project: Caching, Configuration: Debug Any CPU ------
1> Restoring NuGet packages...
1> To prevent NuGet from downloading packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download missing packages'.
1> All packages listed in packages.config are already installed.
1> Caching Framework -> C:\MyProjLocation\Caching\bin\Debug\Caching.dll
2>------ Rebuild All started: Project: Library, Configuration: Debug Any CPU ------
2>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "LumenWorks.Framework.IO". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
2>C:\MyProjLocation\Library\SomeClass.cs(2,7,2,17): error CS0246: The type or namespace name 'LumenWorks' could not be found (are you missing a using directive or an assembly reference?)
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========
None of the NuGet packages were restored (there are over 10 - I removed them from the above output for readability sake).
It looks like NuGet is not even trying to restore the packages for the second project (Library).
I have already tried moving the NuGet targets import below the CSharp targets import in the Library.csproj file, as mentioned here, but it's still not working:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
I am running the latest version of NuGet (2.7.41101.371) on Visual Studio 2013.
Edit: The packages.config exists and the NuGet Package Manager has the Library project ticked with the correct packages.
I had to go into Source Control and delete all of the files in the packages folder (except repositories.config) before NuGet would restore the missing packages. The idea is that you are using package restore rather than checking your packages in to source control. If it sees the packages in source control, it won't download them.
Have you deleted the NuGet.targets file from disk too?
If the NuGet.targets file is there, Visual Studio / NuGet.exe will try to do the MSBuild package restore.
See this doc for more info.
I have the same issue, also on the local machine. Although both Package Manager Console and nuget.exe restore MySolution.sln report that everything is installed, there is no packages folder to be found in the solution directory and no references to packages are being resolved.
I checked all project files and they expect packages to be placed in ..\packages folder, the same folder where the solution file itself is located.
The way I made it work is to run:
nuget.exe restore MySolution.sln -PackagesDirectory packages
This forced nuget.exe to download all packages to the specified folder and all references were restored.
Remember that from NuGet 2.7, the targets file is not supported, msbuild suppose to use some integrated way of restoring packages but it fails very often.
In fact, for my own work I prefer using Paket, which always work, when you get used to it. It also supports target files and nice way to create NuGet packages.
I'm not sure about the science behind this, but it worked for me just now after trying to build a freshly-downloaded Visual Studio project, and getting several MSB3245 warnings followed by a build failure due to missing references:
In Visual Studio, right-click on the project with the missing NuGet references, and select "Manage NuGet Packages..."
The Manage NuGet Packages dialog will open. I also saw a message quickly display and then auto-close, with text along the lines of "Restoring NuGet Packages..."
Close the Manage NuGet Packages dialog (without actually changing anything on the dialog), and retry the build.
Edit: Going back in my TimeSnapper auto-screenshot history (no affiliation with that tool -- I'm just a fan), it looks like there was also a message displayed at the top of the Manage NuGet Packages, along with a "Restore" button: "Some NuGet Packages are missing from this solution. Click to restore from your online package sources."
Although the "Restore" apparently automatically happened for me, clicking that button manually might also do the trick to resolve the missing packages issue.
Had to uninstall nuget packages and do a refresh install in order to make it work properly. This might help some of you facing the same issue
I was having the same problem. In my case, it was a NuGet.Configin the parent directory that was setting <add key="repositorypath" value="C:\CxCache" />. So the nuget restore was copying the packages to a folder I didn't know of. See NuGet Configuration Inheritance.
Deleting the NuGet.Config in the parent directory solved the problem.
On Mac; I commited the code to git and deleted everything (main folder), then downloaded it again. Worked afterwards.

NuGet Package restore IS enabled but I get an error saying it's not enabled

I have nuget package restore enabled in my solution. However, when I try to build the project, I get this error:
This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.
Any ideas how to fix this problem?
I have tried deleting my NuGet.targets and NuGet.exe file and re-enabling nugget package restore. It recreates the files and I get the same error.
Try and see if this helps:
in solution explorer, right click on the project name and select 'Enable Nudget package restore'
also remember to rebuild each of your projects
wait until it gets restored and run the project if it works fine
Please follow below mentioned steps:
Step 1:
Please enable Nuget Package Restore by right clicking on solution [as mentioned in below screenshot]
Step 2: [Follow this if the issue / error is not resolved by following step 1]
Still if you face the issue, please open .csproj file in notepad and check for the package path which might look like
So your solutions directory structure will be like:
\SolutionDirectory\
Package Directory
\SolutionDirectory\packages
Project Directory
\SolutionDirectory\ProjectName\ProjectName.csproj
Please open this .csproj [in which you're getting error in notepad and search for packages path and update it to its relevant path.
For e.g. my .csproj contained, if .csproj file contains ....\packages then update that path with ..\packages
I had already done what the blog post recommends (through the options menu) and it still didn't build.
In the end I removed the Microsoft.Net.Http Nuget Package and Reinstalled it and that fixed it.

Resources