Troubleshooting Issue When Deploy ASP.NET MVC5 to Windows Server
Table of Contents
Introduction
This blog is for when you deploy ASP.NET MVC with NuGet to a Windows server and get an error that assemblies can't be loaded. For example, if you use ASP.NET's bundle feature, which is System.Web.Optimization, this blog might help your problem by changing the project reference setting. Basically, you have to change the reference's "Copy Local" property to true.
Could Not Load File or Assembly
The long story is that after coding your ASP.NET MVC (4 or 5) application, everything works fine on your local machine or local IIS. You also use NuGet as a package manager for your web application, so that during the build, Visual Studio will automatically get the version from nuget.org or other NuGet package providers. My point is everything works fine on your local machine. Now you want to deploy to a web server, assume a Windows server.
So, most of the time it works fine, but sometimes after your deployment, errors appear.
My problem was that my web application used System.Web.Http, System.Web.Http.WebHost, System.Web.Optimization, and Newtonsoft.Json. I noticed that I couldn't find any of these inside my web server's bin folder. So, something was wrong with my NuGet setup, or I thought I wasn't doing something correctly.
The Solution
Should I copy all the NuGet package folders to the web server? When I thought about it, I just needed all the DLLs to be inside the bin folder. Can NuGet do that? I haven't found a way for NuGet to do this directly, but after NuGet adds project references, if the DLL setting's "Copy Local" is set to false, then changing it to true will copy the DLL to the bin folder during the build.

Conclusion
When deploying ASP.NET MVC applications that use NuGet packages, ensure that all required assemblies have their "Copy Local" property set to true in the project references. This ensures the DLLs are copied to the bin folder during the build and are available on the web server after deployment.