Missing Nuget packages - c#

I just got back to an old project of mine and I noticed I had some nuget packages I have to restore, which I've had in the past but than I could go to the console and it would ask me if I wanted to restore my packages.
And the times I haven't gotten that prompt I could always run this command Update-Package –reinstall
How ever none of this solves my problem, the packages I am missign are:
EntityFramework
System.Web.Helpers
System.Web.Mvc
System.Web.WebPages

You have to enable Nuget Package Restore for your project. If that is not working then locate .nuget folder. In windows command line change the directory to .nuget folder of your project and then run
nuget restore Solution.sln
You have to specify the full path of your .sln file.

Related

Some Project in a solution is unable to find System references to NuGet Packages

This is a project that's being cloned from Git, my references are all showing that it could not be found, even though some of it is built in system reference. This solution was cloned from a Git Repository, and I have "Allow NuGet to download missing packages" and "Automatically check for missing packages during build in Visual Studio" checked. Furthermore, the path is Nuget.Config to all the packages is valid.
When I try to do "Restore Nuget Packages" on the solution, it says "All packages are already installed and there is nothing to restore. There is no framework version issues either.
I have tried the following:
Uninstalled Visual studio and reinstalling it.
Clean solution, restore package and Rebuild the project
Reinstalled all the Nuget packages by using update-package PackageName "" -reinstall
Screenshot of Error List
1) First, you should make sure that your VS has installed the related Net Framework SDK. If the git project targets to Net Framework 4.8, you should install the Net Framework 4.8 Developr SDK on your current PC.
2) Second, when you finish it, close VS, delete .vs hidden folder under the solution folder, bin and obj folder of the project.
3) Third, restart your project under then run update-package -reinstall under Tools-->Nuget Package Manager-->Package Manager Console
Update 1
The issue is that the the hintpath of the nuget package from csproj file is not right. After changing the hintpath to the right ones under the PC, all works well.

File was not found after nuget restore

I am using Visual Studio 2017 and pull the source code from TFS server, then build the solution, I got the following error:
Microsoft.Common.CurrentVersion.targets (3863,5): Error MSB3113: The
file "SqlServerTypes \ x64 \ SqlServerSpatial140.dll" was not found.
Then I found this dll file comes from the nuget package sqlserver.types, as I know, Visual Studio will restore the nuget packages when we build the solution.
Why I still have this issue?
File was not found after nuget restore
When you download the nuget package Microsoft.SqlServer.Types from the nuget.org and open it with nuget package explorer:
You will find the sqlserver.types nuget package not only includes .dll from .net framework, but also has native binaries files. These files are designed with x64 and x84, they could not added to lib folder directly. So the package owner adds them to project as content. However, these dll files is setting to ignore by default for TFS, you need to add them manually.
Of course, you can also use the command line Update-Package <package_name> –reinstall to reinstall this nuget package, but this requires you to execute this command every time after you pull the code from the TFS server. Add this native binaries to the source control will Will reduce these unnecessary troubles.
Hope this helps.
You can try this:
Update-Package <package_name> –reinstall

Visual Studio: how to add nuget packages as references when doing "Restore NuGet packages"

I have downloaded all the packages using "Restore NuGet packages" that existed in packages.config
However, they do not appear in the References, so VS is not aware of them.
Is there a way to add them automatically to the reference list? Possibly in 1 step?
The references are tracked as part of the project files and are usually added as part of a NuGet package's initial installation. Restoring the packages will just download them.
This means it sounds like you need to reinstall those specific packages whose references are missing.
To do this, run the Update-Package command in the Package Manager Console with the -reinstall flag on it.
Update-Package <package_name> -ProjectName MyProject -reinstall
Optionally, you can add the -Version flag if you need to stick with a version that's not the latest, just make this version number match that stored in your packages.config file.
Or alternatively, to reinstall all packages for a given project:
Update-Package -Reinstall -ProjectName <project_name>
I too have VS 2017. However, I haven't encountered any problem with Nuget packages.
Anyway, try this: Right-click the References folder in the project, then click "Manage Nuget Packages" then click "Restore".
If that doesn't work, close VS, delete all files in bin, obj and packages folders and then repeat the steps above.
Also make sure the items "Allow NuGet to download missing packages" and "Automatically check for missing packages during build..." are checkekd in Tools/Options/Nuget Package Manager setting as follows:

After clone of web site project nuget restores packages but references are not found VS 2015

We have moved a legacy web site to git in TFS, and anytime the project is cloned nugget restores the packages per the package.config, and adds them to the packages folder. The subsequent build fails due to not being able to find the assemblies added through the nuget restore.
If you do a update-package -reinstall and the project builds successfully. Is this expected behavior or do I have a setup issue? The previous repo had the packages being checked in to eliminate this issue but I'd like to avoid that.
Is this expected behavior or do I have a setup issue?
Yes, this is expected behavior for NuGet, so do not worry that it is a setup problem.
NuGet Restore only restores files in the packages directory (\packages folder ), but does not restore files inside your project or otherwise modify your project. For example, if a package has added some reference DLLs or other files in your project, if you delete any of these files, they will not be re-added when restoring this package. This may cause the your project to not be able to find the missing dependencies when building.
Besides, the expected result is that the references should be used normally without broken after restore packages. In this case, we will not need to spend extra time using update-package -reinstall command line to uninstall and reinstall packages.
So use the "Update-Package -reinstall" command to force reinstall the package references and content files into project in order to resolve those references that were broken after packages restore.

NuGet has problems with missing packages, how to restore?

When I try to compile my program I get the following error:
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=317567.
Now when I right click on the solution and press
All packages are already installed and there is nothing to restore.
I tried manually reinstalling every package which didn't solve the problem, I tried reinstalling NuGet but that didn't help either and I even tried reinstalling visual studio.
I also tried moving the package folder from the tfs folder to overwrite my package folder but that didn't solve anything. I also tried redownloading them with this package missing, that didn' t solve the problem either.
Anybody know how to restore the nuget packages?
Use Package Manager Console in Visual Studio to run this command.
1.This will restore all packages from solution
nuget restore YourSolution.sln
2.If you want to reinstall the packages to the same versions as were previously installed
Update-Package -reinstall
Honestly, whoever developed the NuGet command for VS needs to go back to the drawing board. They totaly missed the fact that sometimes these DLL(s) and/or files get corrupt or deleted. a "NuGet Get-Packages -Force" option would really save their bacon. The only GAP I see is that VS and the Package console does not allow you to invoke a forced download from NuGet. Even clearing the cache via VS is useless.
I ran into this issue when I tried to build my project on a computer where the packages-folder did not already exist in the solution root.
When the project file was initially created, it seems VS2019 added the following into the project file:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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 {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>
From what I understand those settings are deprecated nowadays, no idea why VS inserted it in the first place.
Anyway, after removing those lines VS restored the packages and built the solution correctly again.
It's probably a good idea to clear the Nuget Cache by deleting the contents within this directory: C:\Users\{your_username}\AppData\Local\NuGet
All you need is that:
Open the Package Manager Console and run this command: Update-Package -reinstall
P.S: VS2017 and above NuGet Package Manager is included with Visual Studio, no need to install anything else.
The problem with the functionality of the NuGet package can also be caused by the fact that NuGet package is requiring certain dependency that the project does not meet.
NuGet package can have a declared dependency in Dependecies section, e.g. .NETFramework,Version=v.4.6.2 while the project is targeted to an older version (Target framework: .NET Framework 4.6.1.).
Instead of the NuGet system notifying the user of this fact, the project simply does not compile.
In my case, I have different Nuget configurations, and somehow the HintPath in the project file didn't fit.
Maybe you should check if the HintPath leads to the right NuGetPackages folder.
You should also check the following entries at the top of the file:
And at the bottom of the file:
All these paths should point to the right NuGetPackage folder in your file structure.
In my case the problem was solved by deleting the "obj" folder(s) and then rebuilding the solution.
The "obj" folder had several NuGet related files that still referred to version 0.0.2 of a package while all projects in the solution were already using version 1.0.0 of that package. Building the solution failed with the error message "package with version 0.0.2 could not be found". The solution with build folders included was recently copied from another machine.
Well it's probably a bad way but I found that it works if I just delete the line
http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
from the project.csproj , not sure if this is going to cause problems later on but it works for now.

Categories

Resources