I created a NuGet package and I was able to successfully install it in another .NET solution. But I'm not able to add a reference to the NuGet package from the other .NET solution.
For example, the NuGet package has a class with a namespace like MyCorp.SecurityApi
. I'm currently not able to add a using directive for that namespace in my other .NET solution. For example, using MyCorp.SecurityApi
directive returns this compilation error:
The type or namespace 'MyCorp' could not be found
Any idea what the issue might be or how to debug it?
I would first try to do an
Update-Package -Id <package_name> –reinstall
as explained in Mikaal's answer.
But in some cases, this could also fail because the packages
folder got corrupt. Depending on the platform, it is located in different paths:
In .NET, this folder can be found within the project directory (typically, in the same folder where the solution file *.sln
is).
In .NET Core, you can find it by pasting the following line into the file explorer's path (open it via WIN + E, then paste the line above in the path textbox):
%appdata%\..\..\.nuget\packages\
There, try to find the package and delete the folder and its contents. You can also find the path if you go to dependencies in Visual Studio, Packages, right-click on the package and copy the path from the properties window. Note that you might need to close Visual Studio before deleting it, as the files might be locked.
Important: Verify that it isn't referenced any more in Visual Studio (dependencies). If it is, remove any dependencies.
Finally, open the Package manager and add the package (i.e. right-click on the project, select "Manage NUGET Packages...", switch to the Browse tab, select the package and click Install).
Make sure you double check the “namespace” name with the “References” in your solution explorer, whether it exists or not. If it doesn’t you should consider reinstalling. Use the following command in Nuget Package Manager Console:
Update-Package -Id <package_name> –reinstall
Or this to restrict the re-install to a particular project only:
Update-Package <package_name> -ProjectName MyProject -reinstall
If you’re still unable to do that, try manually adding your relevant .dll to your project and see if it works properly. If it does than most probably the problem lies with the configuration of that nuget package, in which case I would recommend you to go through these docs and narrowing down the problem.
A problem could be due to:
I suggest you to check mentioned above reasons, hope it helps to you
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