NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

Nuget package restore not working vs2019 #8852

Closed shaipetel closed 4 years ago

shaipetel commented 4 years ago

Building a project throws this 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=322105. The missing file is C:\Repos**\.nuget\NuGet.targets.

I checked and nuget package restore is enabled.

I closed and reopened visual studio, tried to build, opened nuget manager but it is not building and not restoring missing packages.

I followed this article: https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore-troubleshooting Which suggests if the packages are not restored automatically to file an issue here.

Please advise.

using visual studio enterprise 2019 version 16.3.9 the project opens and works fine on a different computer with vs2017

shaipetel commented 4 years ago

upon further checking, it seems visual studio thinks these packages are installed, however all their dlls are missing and not available.

shaipetel commented 4 years ago

More info: all packages are there, restored correctly. the DLL references are missing. Running: Update-Package -reinstall in the Package Manager Console removed all references in my project and re-added them one by one, but they all still seem to be missing (yellow triangle).

Any help would be appreciated.

shaipetel commented 4 years ago

Issue fixed by manually editing the csproj file and removing the NuGet entries there (Thanks to Kevin). Just FYI in case anyone else encounters this. Still there is clearly a bug in the NuGet system.

karann-msft commented 4 years ago

@shaipetel - this is repo is for docs issues. For product feedback and bugs, please use the Home repo. For now, I'll transfer this issue to the correct repo.

feilongsword commented 4 years ago

I have the same trouble too. Do you or anyone else find a solution?

shaipetel commented 4 years ago

Yes, see my previous comment regarding editing the project file and removing the NuGet there.

nkolev92 commented 4 years ago

The packages.config project management style by design hardcodes the references to packages inside the csproj file.

This happens at install. This also means at uninstall time, NuGet needs to figure out which references it added at install time and remove them. This works fine for the most part, but it can be a problem if a package uses install/uninstall scripts. Then it's on the package author to help NuGet does the right things.

Note that in PackageReference we removed the concept of install/unistall scripts for this exact reason.

Update-Package -reinstall in the Package Manager Console removed all references in my project and re-added them one by one, but they all still seem to be missing (yellow triangle).

There's many ways this can go wrong. Makes me think that some references to some earlier packages might not have been removed or they were potentially manually edited at which point we're going into unsupported scenarios.

Would you be able to provide us a repro? Unfortunately without understanding exactly what the problem is, we won't be able to help much.

Thanks.

gojimmypi commented 4 years ago

@nkolev92 and @shaipetel I believe I am having this exact problem of a fetched package missing the DLL. I have a sample repo to demonstrate:

git clone https://github.com/gojimmypi/ulx3s-examples.git
cd ulx3s-examples\
git checkout SSD1331

In Visual Studio, navigate to ulx3s-examples\nanoFramework\nanoFrameworkSSD1331_demo and open the nanoFrameworkSSD1331_demo.sln solution in Visual Studio 2019.

Note that I have the nanoFramework extension installed. Here's my version info:

image

image

When initially creating this solution, adding NuGet packages via the Visual Studio interface worked fine. Note however, the NuGet packages are excluded from my repo, expecting that any clones will pull their own fresh binaries.

First, right-click on the solution and select Restore NuGet Packages. Nothing happens: image

I assume this is due to the way I saved my files in GitHub, excluding the packages. I'd be interested in knowing if I should do something different.

So next, go to Tools - NuGet Package Manager - Package Manager Console, ensure the package source is set to nuget.org and type:

Install-Package nanoFramework.CoreLibrary -Version 1.6.0-preview.1

result:

PM> Install-Package nanoFramework.CoreLibrary -Version 1.6.0-preview.1
Package 'nanoFramework.CoreLibrary.1.6.0-preview.1' already exists in project 'nanoFrameworkSSD1331_demo'
Time Elapsed: 00:00:00.0511662
PM> 

(note the packages directory is still empty)

So instead, reinstall everything. This is where things get interesting:

Update-Package -Reinstall -IncludePrerelease

all packages appear to be successfully install, however the packages\nanoFramework.CoreLibrary.1.6.0-preview.1 directory is missing the respective DLL, despite the fact that when initially adding it to a new project, it is there. Other libraries that were just freshly downloaded all have a DLL in the respective lib directory.

Note that if you go to the nanoFramework.CoreLibrary 1.6.0-preview.1 and manually download the zip file, the DLL is there.

edit: I see the same result in VS2017:

image

image

image

The DLL is missing from the lib directory.

marqdouj commented 4 years ago

I believe I am having the same (similar) issue. I've created a NuGet package that contains 2 .NET Framework 4.7.2 dlls in the files section. If I install the package to a new .NET Framework 4.7.2 class library and select packages.config the second dll is missing and won't install (it shows up with warning icon in the project references). If I change the project to packagereferences then both dlls install correctly. Am I missing something here?

marqdouj commented 4 years ago

I did some more digging... I moved the second dll to it's own nuget package - same results; the dll won't restore properly unless the project is using packagereference. The only difference is that this dll is a WPF user control library.

Any ideas?

nkolev92 commented 4 years ago

@gojimmypi

The reference in your csproj has <Private>true</Private> and that's the override for copy local, so you are opting out of the copying.

@marqdouj

If I change the project to packagereferences then both dlls install correctly. There are some differences in how packages.config and PackageReferences work. Unfortunately I'm having trouble following the scenario without a repro.

nkolev92 commented 4 years ago

At this point, we are deviating from the original issue. This issue is capturing a very broad topic and we haven't gotten more info from the OP so we can scope it.

As such I'll close this issue. We'd be happy to engage in a new issue if my suggestions above do not address your problem.

Thanks

Pedroma34 commented 2 years ago

The way I solved it: delete the entries in packages.config and reinstall your packages