Visual Studio references not resolved until clicked on - visual-studio

References (specifically from internal nuget server) seem to be unresolved after using restore nuget packages. The project builds fine but anything that uses these references show as errors in the code until you manually expand references and click it (shows a warning on the reference, when clicked it resolves and removes warning).
Is there an easy way to auto resolve them without going through every project and clicking the refrerence manually?

Is there an easy way to auto resolve them without going through every project and clicking the refrerence manually?
Please try to use the NuGet command line in the Package Manager Console:
Update-Package -reinstall
to force reinstall the package references into project.
NuGet Restore only restores files in the packages directory (\packages folder ), but does not restore files inside your project or otherwise modify your project.
Check the similar issue for some more details.

Related

Nuget Update failure in Visual Studio 2019

I am having a strange (new) issue with Nuget in Visual Studio 2019 (v.16.9.0).
The Solutions are all ASP.NET Web Apps (MVC). I run on a local LAN. In the Nuget Package Manager 'Allow Nuget to download packages' and 'Automatically check for missing packages during build are both selected. I am using Packages.Config for management and the source is https://api.nuget.org/v3/index.json. VS is able to communicate via the Windows Defender Firewall. The target framework is .Net 4.7.2
The first issue is when I do a package restore after deleting the packages in the folder, it shows this error: The requested operation cannot be performed on a file with a user-mapped section open.
After I do the build, the files are being created correctly, including the new/existing DLLs. These replenished/refreshed DLLs work perfectly and the program runs. The strange part, however, is that the relevant NUPKG file has zero content (which is obviously triggering the error). The message eventually disappears after completion of the DLL downloads I assume. All good so far but with zero content in the NUPKG file.
When I now try to update a package things go awry, the Error List shows:
An error occurred while trying to restore packages. The file is not a valid nupkg. File path...
Then after a full restart of VS, I get this:
An error occurred while retrieving package metadata for 'ABC.3.5.0.2' from source 'I:....\packages'. 'ABC' being the first file in the package list. It therefore appears to be failing because the relevant NUPKG has no content.
I am able to paste any file freely to the packages folder and its sub-folders, indicating that there is no lock on the files. Also VS is able to write the rest of the package structure to the folder without issue.
IMHO this must mean that something is specifically locking/blocking the NUPKG files (or deleting their content during creation perhaps?). A search reveals nothing that I can see.
I even tried creating a brand new solution. During creation, the identical error message above popped up a warning. I also tried a few other of my existing solutions and got the same result. I updated VS and then I even did a full VS reinstall to the latest version, all to no avail.
I first noticed the issue after defining dependencies during an Azure Web App deployment (the Azure deployment tool optionally allows for updates to Nuget packages). After the Nuget update failed I set the option to blank and deployed anyway, the idea being to manually update the packages later. I cannot be certain, but I think this is when I discovered the issue. Could this process have changed a VS config setting somewhere perhaps?
Before the reinstall I opened the devenv.exe.config from inside VS and changed the IPV6 setting to false. No luck, so I have changed it back. I also did a test on one of the packages, downloading the package from the Nuget site directly and replacing the VS downloaded version, but I get the same errors.
Install failed. Rolling back... Package 'System.Buffers 4.5.1' does not exist in project 'ClickAuth_Graph' Package 'System.Buffers 4.4.0' already exists in folder 'I:\My Drive\Backups\ClickAuth_Graph (01_03_21)\packages' Added package 'System.Buffers 4.4.0' to 'packages.config' Removing package 'System.Buffers 4.5.1' from folder 'I:\My Drive\Backups\ClickAuth_Graph (01_03_21)\packages' This file is not a valid nupkg. File path...\packages\System.Buffers.4.5.1.nupkg Central Directory Corrupt An attempt was made to move the file pointer before the beginning of the file. At line:1 char 1 • Update-Package System.Buffers +CategoryInfo NotSpecified: (:) [Update-Package], Exception o FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand
For the record I have one stale Nuget package in the portfolio. I don't use Github, but a repository was set upfront. I have not recently committed anything to Github.
Is there an expert out there that can help?
What you described is in a mess. And please try the following suggestions:
1) first clean all nuget caches or delete all cache files under C:\Users\xxx\.nuget\packages and I:\My Drive\Backups\ClickAuth_Graph (01_03_21)\packages.
I think that you have download the valid nuget packages on it and if your local exists the same name,version nuget package, it will always use the local wrong nuget package. So you have to delete them and then download the right package from the nuget package source.
2) enter Tools-->Options-->Nuget Package Manager-->Package Sources and make sure that you have enabled nuget.org package source, and if you have other own feed which you want to use, also enable it.
If not, please try to close VS, delete nuget.config under C:\Users\xxx\AppData\Roaming\NuGet. And then restart VS to re-generate it. Then, re-add your own feed if you have it.
3) run update-package -reinstall under Tools-->Nuget Package Manager--> Package Manager Console and then also delete bin and obj folder of your project.
4) you could also try to disable Azure deployment tool
Besides, if you have other solution level nuget.config, please check whether its content is suitable for your project. And if it is useless, you could remove them.

nuget references appear missing after restore but aren't

After I restore nugget packages my solution builds but intellisense says the references don't exist and I get what looks like errors but are false positive. This only seems to happen in my test projects. The only way I have found to fix it is to go into the references for each project that reports errors and view the properties. Once I open one the broken reference in the properties window all of the broken references for that project magically get fixed.
Just to be clear - the restore is working - its just VS doesn't think so; it puts the missing reference icon on the reference and intellisense reports errors on any code that uses the reference. It all builds and runs fine
nuget references appear missing after restore but aren't
You need use the NuGet command line in the Package Manager Console:
Update-Package -reinstall
to force reinstall the package references into project after restore nuget package.
NuGet Restore only restores files in the packages directory (\packages folder ), but does not restore files inside your project or otherwise modify your project, in other words, NuGet will not reinstall the package references in the project. After you restore the packages, the packages are re-download to the packages directory, so the package references are broken temporary, then the intellisense reports missing reference errors on any code that uses the references.
To resolve this question, you can use the "Update-Package -reinstall" command to force reinstall the package references, after that, all references are reinstalled, this weird behavior will disappear.
Hope this can help you.

NuGet downloads all packages, doesn't update references

I have my project set to Allow NuGet to download missing packages as well as Automatically check for missing packages during build in Visual Studio. In my solution folder, there is a packages folder and it contains everything that I need for my project. However the references to them in the project are still broken.
I have tried removing the references and adding them with NuGet, but NuGet says the item is already in the project (it is in the packages folder) even though the reference is there and the project can't build. The only way that I can seem to get around it is to manually go into each of the packages in the packages folder and select every .dll.
Is there a better way to do this?
Open package manager console and type:
Update-Package -Reinstall
This should refresh all your references based on each project's packages.config file.

Creating a vs.net 2013 solution with multiple projects, nuget is causing real problems

When other developers get the vs.net 2013 solution from TFS, Nuget doesn't seem to work as expected and many of the individual projects in the solution do not have the required dll's downloaded (although they are defined in the packages.config file).
If I go to view the installed packages, it shows up as they are installed and the correct projects are selected.
I went into console and ran:
Update-Package -Reinstall
After doing this, my packages.config file was truncated for whatever reason and 80% of my packages were removed from the config file!
What should I be looking into as it is either I have setup the solution incorrectly or nuget just isn't reliable.
Thoughts?
First of all make sure that NuGet Packages Restore is turned ON.
This forces to restore missing binaries directly from NuGet server. You can right click on Solution and enable this option as follow:
Make sure that .nuget folder that contains nuget.exe is created under your Solution.
You'll want to make sure that you have automatic package restore turned on in VS 2013. You can do this in the options.
Then, when you build, VS should grab the packages for you. If you want to manually restore the packages or do it from powershell, you'll want to use the command nuget.exe restore in the folder your solution lives in.
If you're using custom package sources, you'll want to make sure you specified them in your nuget.config file.

VS 2012 not using the dependencies downloaded by NuGet

I checkout a solution from a repo which is not owned by. The solution and/or the projects are not developed by me either. I follow this guide from here. This is the summary:
What worked finally was to
check Tools|Options|package manager|Package restore right-click the
solution and "enable package restore" right-click a project in the
solution and "Manage nuget packages". Then you will finally get a bar
across the top of this UI with a message that some packages are
missing, click to get them. Clicking this button gets the packages.
So, I click on restore and NuGet seems to download the packages. However, when I try to build the project, it still complains that the dependencies are missing. I look at the packages folder in the solution folder and see all the necessary dependencies. But, for some reason the project is not correctly linking to it.
In other words, Solution/packages exists with all the libs but when I try to build the solution and/or project, I get a build fail. Does anyone know what is going on?
Thanks.
EDIT: For clarification, under warnings, I get
Warning 18 The referenced component 'Microsoft.Practices.Unity' could
not be found. BlueFin
EDIT 2: For another clarification, if I add existing references and go to the packages folder packages/lib/thefile.dll, it will compile properly and work. The question is, nuget should be doing this automatically for me right?

Resources