Nuget does not update Package References in ASP.NET website - asp.net

About: I have a ASP.NET website (not Web project) with 3 class library projects in the solution. Earlier I was using SVN but now Git is used source management. I have installed the git locally on a computer (used as server) and using it for merging the source code from other developers. Also, I am using Visual studio 2015 community edition which provides the tools to work with git.
Problem: After cloning the project from the master repository, I build the project to run it. Building the project shows a dialog box saying "Package Restore is in progress". This process creates a folder named "Packages" and that folder includes every package listed in the packages.config file. But after restoration completes, the project throws the following exception:
This exception shows for each package (Autofac here).
The type or namespace name 'Autofac' could not be found (are you missing a using directive or an assembly reference?)
Work around To Solve this problem, I need to uninstall each package and installed it again and problem is solved. This thing I need to do again and again for each developer machine, which is frustrating and time consuming too.
Does anyone has faced the same problem working with Nuget, git and website in ASP.NET.

I faced a problem like this before. In my case, the reason was that I changed the project path (moved the project to another directory), and the path of the packages directory (that contains the NuGet packages) was stored in the csproj file for the old path, that is VS cannot restore NuGet packages. The solution for this was to edit the csproj manually and make it referring to the correct new packages path.
If this doesn't work for you, you can still use your workaround, but using the following PowerShell command (in NuGet Console) for simplicity:
Update-Package -reinstall -Project Your.Project.Name
Note: project name doesn't contain csproj extension, just the project name

It is good practice to not put third party packages into source control. It bloats your repository (even on a large web application, the size of the external packages will massively out weigh your code).
If NuGet package restore is slow, you could look at using a local cache (this can be as simple as a shared folder) or a better internet connection.
That said, you should only have this problem once per machine. While the packages are downloading you could be giving the new team member an overview of the design…

Make sure that all of your projects are using the same target framework, when this isn't done you can often get the
type or namespace [name] could not be found
warning.
To do this, right click each of the projects in the solution explorer > Properties > Application tab > Target Framework. They should all be the same or there will be incompatibilities between the references in your projects. Here's a question regarding this, hopefully this helps.

The main reason is there no Autofac reference in packages.config file.
When you see on the screen Restore packages message box this mean that nuget package manager is trying to install all the packages which are missing in the package folder.
Try to do this step:
In Visual Studio Solution Explorer pick the project and via context menu pick Unload project
After project was unloaded via context menu pick Edit your project
Go to section group and find you Autofac Reference section
If HintPath doesnt looks like ..\packages\Autofac.4.1.1\lib\net45\Autofac.dll (Actual for 4.1.1 version) remove the Autofac reference Item
Save csproj file and reload project
Install Autofac via NuGet Package manager
Commit and push changes to git repository

Had the same problem with VS 2019. In ASP.NET, packages are updated via the .refresh files that appear in your bin folders. If these aren't checked into Git, they wouldn't be copied down to your cloned repro.
I added the .refresh files for all of my package dlls, made sure the versions and paths in the .refresh files were correct, and now everything updates as expected.

Related

ASP.NET website update assemblies references without modifying .refresh file

My solution file contains a website project and some library projects. My website project is depending on these library projects and some other nuget packages. I have to build my .sln by MS Build. By executing nuget.exe all dependencies are loaded, but their references not updated to packages folder. When I google my problem I found the following solution.
https://www.codeproject.com/Articles/823752/ASP-NET-Website-Project-External-Assembly-Referenc.
But it did not solve my problem as I do not want to keep bin folder and I also do not want to keep the .refresh files of all the DLL. I need to load all external dependencies and referenced automatically, when I build .sln file.
ASP.NET website update assemblies references without modifying .refresh file
If I understand you correct, you can add a class library project to the solution, and add reference to the class library project to your website. Then, add the nuget in the class library, not the website project.
Then you could use nuget.exe update those nuget packages for the solution, like:
nuget.exe update "<YourWebsitePath>\WebSite1.sln"
In this way, When your build website, it pulls in all the class libraries' dependencies in turn.
If I am not understand you correct, please let me know for free and you can share a simple sample about your question, so that we could understand it more clearly.
Hope this helps.

Could I remove or move the folder NuGetFallbackFolder?

Could I remove the folder C:\Program Files\dotnet\sdk\NuGetFallbackFolder\ or move it to other folder? (better not in disk C)
If could remove, how to remove? delete the folder directly? any side effects or damages?
If could move, how to move? target folder like D:\NuGetFallbackFolder? How can I do it?
This folder contains a set of Nuget packages that the SDK expects to use. It's used as a nuget source whenever dotnet is trying to resolve nuget packages. Removing is generally similar to removing your nuget cache: .NET Core will simply not find the packages and download them into the (normal, non-NuGetFallbackFolder) local nuget cache.
Some distributions of .NET Core do not contain the NuGetFallbackFolder. The only consequence is that dotnet will download all those packages as soon as it needs them (possibly on the first SDK command).
If you move it around, .NET Core won't know about the new location and just treat it as if you had deleted the directory. On Linux, I would use a symlink to point from the old location to the new one. I don't know if Windows supports that.
after searching the internet and trying some in vain:
deleting the NuGetFallbackFolder in the corresponding .NET SDK and
repairing in Windows Uninstall Programm helps really
in my case it worked : the build process in solution got all new in

Build fails due to different package location

I'm new to realm db and tried to integrate it in our mobile app (Xamarin.Ios using Visual studio).
I've added the nuget to the PCL project as well as to the executable project
when building, the build fails with the following message:
1>C:\Projects\CoachApp-Fork\ExternalPackages\Realm.0.74.1\build\Realm.targets(6,5): error MSB3030: Could not copy the file "C:\Projects\CoachApp-Fork\Build\Solutions\packages/Realm.0.74.1/tools/RealmWeaver.Fody.dll" because it was not found.
There seems to be a build task in realm that tries to copy the dll, however in our solution, the nuget packages are located at a different location (configured via Nuget.Config).
any ideas how to resolve this? i cannot simply change the nuget package location, as the build server relies on this...
That was my clever trick you broke!
The problem is the location of the DLL for Fody is quite restrictive and yet the Xamarin templates have two different relative package directory locations depending on you having a multi-target project. (This was an improvement to cache packages per-solution, I think sometime in 2015.)
Can you put your own manual copy step into your build, at least for now, to put it there in advance? I realise this isn't an optimal solution but might work as a band-aid.

What are the differences between references and packages in monodevelop ide

I created a new asp.net project, and I am using the monodevelop as the ide.
On the left hand side in the explorer I can see two sections, one is called reference and the other called packages.
I assume that references are the library or dependency files like the jar equivalent of java. Then what are the packages section for?
Is it also another kind of dependency?
Can anybody help me understand the meaning of those two sections?
I assume you mean References and Packages. There is no Resources section/folder when I create an ASP.NET project in MonoDevelop.
The References folder will show the assemblies that are being referenced by your project. An assembly is equivalent to a jar file.
The Packages folder shows you the NuGet packages that are being used by your project. A NuGet package will typically provide assemblies and these will be shown inside the References folder but within a From Packages folder. A NuGet package may include other things, such as content files, which are added to the project, or custom MSBuild targets which modify the build behaviour.

The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' Error?

I've downloaded a website and in VS express open it through file => open website. When I press F5 to debug I get build errors:
The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft'
I guess I'm missing a reference but how come it works on the server? References for these projects can be found in the bin directory right?
Under website => start options => build I've set the following: "Build web site" and target framework ".net framework 4" this is the same as the server.
I guess it's looking for a dll that contains Microsoft.aspNet which probably is in totallyUnrelatedName.dll in the folder scratchYourHeadAndLookSomeMore
Could someone help me out and give me a clue as to why Microsoft.aspNet would be missing from my computer?
I'm tempted to quit this job since all projects are web projects without any documentation that won't run locally but do need major changes. Client has no problem to implement changes on the live site but I do.
Go to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution.
Click on the Online Tab.
Search for Microsoft ASP.NET Identity Framework.
Install this package.
Rebuild Solution.
I guess I'm missing a reference but how come it works on the server? References for these projects can be found in the bin directory right?
Not if the used libraries are installed on the server. You might want to install them on your workstation too, or add the proper references (for example via NuGet) and do a bin-deploy.
On how to find out which libraries you're missing: find class names, not namespace names.
I had this error message too so I reinstalled all of my nuget packages again via the package manager console. Unfortunately this did not sort my issue and after loading up a completely separate project within a different solution to the one in which I was experencing: The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' error, I noticed that it was occurring there too. This meant that there was an issue with my Visual Studio rather than a problem with individual packages or projects.
It turns out that my MEF Component Cache was corrupted - to fix this I deleted my Visual Studio's component model cache folder which can be found here:
%LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache
Mads Kristensen has created a Clear MEF Component Cache Visual Studio extention which you may find useful:
Clear MEF Component Cache
i have the same issue, on mac vs 2019,
reinstall all Associated nuget of the error you get,
you caמ find them on simpale search on google "nuget + " for example "nuget AddNewtonsoftJson",
then go to "project > manage nuget packages" ...
I try all above solution but It did not resolve my issue.
If still you cannot resolve this following solution might help you
https://www.nuget.org/packages/DotNetOpenAuth.AspNet/
NuGet Installation:
Go to Tools -> NuGet Package Manager -> Package Manager Console
PM> Install-Package DotNetOpenAuth.AspNet

Resources