I'm experiencing rather a strange issue with NuGet (most recent) and VS2012. I have a multi-project solution with NuGet package management enabled and as long as I'm using Debug|AnyCPU configuration, it all compiles and application runs correctly. As soon as I switch to Release|AnyCPU, it seems like all the NuGet assembly references were gone and the app obviously do not compile. Strangely, I can see all the references in NuGet Manager UI for all the correct projects.
Did you ever experienced similar issue and do you know how to fix it?
Rebuild did not helped. NuGet references were set up while Debug configuration was set.
NET or . NET Core project. After you install a NuGet package, you can then make a reference to it in your code with the using <namespace> statement, where <namespace> is the name of package you're using. After you've made a reference, you can then call the package through its API.
Restore by using MSBuild You can use msbuild -t:restore to restore packages in NuGet 4. x+ and MSBuild 15.1+, which are included with Visual Studio 2017 and higher. This command restores packages in projects that use PackageReference for package references.
In Tools -> Options -> NuGet Package Manager -> General you need to select the "Allow NuGet to download missing packages" option which allows NuGet to restore and the "Automatically check for missing packages during build in Visual Studio" which enables on build restore.
Open Visual Studio, go to Tools -> NuGet Package Manager -> Package Manager Settings menu. Click Clear All NuGet Cache(s) button in options dialog then clearing process is started. Once NuGet cache location is cleared, click ok button.
Once again, I'm answering my own question...
The point was, I was changing the structure of solution and moved some projects around. That means, you get invalid relative paths in .csproj files per project. Which is OK, as long as you don't change the depth of the structure, which I did.
For unknown reason, debug build went just fine with invalid paths (probably the assemblies are gathered some other way, as I manually deleted bin and obj folders and cleared solution, etc...). But for release build, it tried to obtain the assemblies from the (wrongly referenced) packages/ directory.
NO PART of NuGet process found/reported this issue and in all UI consoles and even in the NuGet PowerShell Console itself, everything seemed just OK.
The solution is obvious. Edit the .csproj files for affected projects (I was actually guided to the issue by filtering warnings and finding out, only some assemblies were affected and those were from outside of the main solution directory) and change the paths of assembly references to correct NuGet packages folder.
On the side note: This is THE problem of NuGet (and possibly VS) references handling. It is trying to use some relative paths instead of adding some variable like ${SOLUTION_ROOT} or ${NUGET_ROOT} or ${PACKAGES_FOLDER}. If it was done by variable replacement, one could use the same projects in multiple solutions, without breaking NuGet packages configuration. At least I haven't found the way to share the same project folder across multiple solutions.
I was able to resolve this issue by uninstalling, then installing the Nuget packages my project was using.
Late to the party, but it may help someone. This issue can occur if you change your nuget repositoryPath
(perhaps via nuget.config), to a different path, mid project.
e.g.
As mentioned by @Baron, reinstalling will resolve all this mess. I'd also recommend deleting all bin/obj/packages from your working tree, to ensure you don't have any crud.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With