MVC bin folder, why are there so many dll files - asp.net-mvc

I have more than 50 dll files in the bin folder in my mvc project. As someone who has just switched from web forms to mvc, why are there so many dll files. Only 2 files belong to me, K20.DAL and K20.BLL files. Are there any IIS configurations so as not to upload other DLL files to the server for each project?

All the other DLLs are present because they are referenced by your K20.DAL and K20.BLL project references. Few DLLs are part of MVC framework. When ever your application is running, only the DLL which is needed by your code currently executing will be loaded into AppDomain memory. This is on-demand-loading. After the code execution is over, the DLL will be unloaded from the memory. If some DLL which is needed by your code, but if it is not present, then your code breaks. There may be some shared DLLs also used by your application which will there in .net GAC assembly folder but not in bin folder.
So there is no harm to deploy these DLLs to server if you are not sure whether your application is using them or not.
Hope this clarifies your doubt.

Related

azure remote website does not show all my code files

I am trying to remote debug my asp.net mvc site on azure. I published my project in debug mode and then look into my remote website folders and it only shows 1 csharp file as opposed to all of them. I don't know why I can't see all of them.
Actually, it's interesting that there were any .cs files published. Assuming you published to Azure directly from Visual Studio, the MVC app gets compiled first and then deployed, and there shouldn't be any .cs files in the compiler's output.
From msdn:
The compiler produces executable (.exe) files, dynamic-link libraries
(.dll), or code modules (.netmodule).
Publishing in Debug mode doesn't change this. From msdn:
The /debug option causes the compiler to generate debugging
information and place it in the output file or files.
By way of comparison, all of the "static" files in your project (Views, style sheets, scripts, etc.) get deployed in the same directory structure as your project. But all C# files (Controllers, model classes, custom attributes, etc.) get compiled down to the executable, as quoted above, which then gets placed in the bin folder.
As an experiment, try publishing your website to your local machine and inspect the target folder. Assuming your solution contains only the one project (and assuming it's called GiantCorp.AwesomeApp.Web), it will probably be structured similar to this:
bin/
GiantCorp.AwesomeApp.Web.dll // <= all your C# classes compiled to a single executable
GiantCorp.AwesomeApp.Web.pdb // <= if you compile/publish in Debug mode
System.dll
System.Web.Mvc.dll
....etc for any required library or .NET assembly dependencies
Content/
bootstrap.css
Site.css
Scripts/
jquery.min.js
giantcorp.app.js
....etc
Views/
Home/
Index.cshtml
About.cshtml
AwesomeFeature/
Index.cshtml
Shared/
_Layout.cshtml
_ViewStart.cshtml
Web.config
Global.asax
Web.config

ASP.NET MVC 5 - References vs bin folders?

I am trying to set up an ASP.NET MVC 5 project in Visual Studio 2013, based on another project I have been given by somebody significantly more experienced than me. In his project, there is a References folder, with references to System, System.Core etc., together with third-party libraries. However, this folder does not exist by default in my new ASP.NET MVC 5 project. Instead, I have a folder called bin, which looks similar to References, and I can add references to dlls. What is the difference between the References and bin folders? Why does his project have one, and mine has the other? Thanks.
Your references 'folder' are assemblies (DLLs) that are referenced by your project. The reference is held in text in the project file.
The bin folder is used for compilation of your project. At compile time, the references in the project file are resolved (located for use by your project when it's running). This may be copying them from another location on disk, downloading a nuget package or using a version from the GAC. If the assembly is going to be copied down from another location it will be copied into the bin folder where all the files necessary for the application to run are stored.
UPDATE:
A different project type had been added and hence the references folder was not visible. Adding an ASP.NET Web Project into the solution solved this.
In Visual Studio 2015:
File >> New >> Project (Web Application)
A Project will have a References node when viewed through Solution Explorer in the IDE. If viewed with a file explorer (Windows Explorer) there is no Reference folder. References are stored in the project (csproj or vbproj) file using plain xml/text.
File >> New >> Web Site
A Web site does not have the References node nor a project file. In Solution Explorer right-click on the Bin folder or the root node to add References. References can be seen in the Property Pages (right-click root node).

Deploying a Solution with multiple projects on IIS7 - Missing DLLs

I'm trying to publish a solution that contains several projects -one of them is MVC- to IIS7.
When the MVC project is published and some views are being accessed I get the following error:
Could not load file or assembly 'NHibernate.Mapping.Attributes, Version=3.2.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The system cannot find the file specified.
This happens because the view I'm trying to access is calling a function in another project in that solution and needs this library!
but this library is not contained in the MVC project!
I was able to solve it by referencing that DLL in the MVC project! but I need another solution, because it doesn't make sense to reference every single DLL in all the other projects!
I'm using the "Web Deploy" publish option for the MVC project, is there another way that I can publish it and make it work without referencing all the DLLs from all the other projects?
There is an article on how to deploy assemblies that are not referenced by your MVC project directly:
http://haacked.com/archive/2011/05/25/bin-deploying-asp-net-mvc-3.aspx
Basically you need to create a folder in your project called _bin_deployableAssemblies and add your assemblies to it. They will get deployed with the website.
Here is a quote from the article:
So here’s the kicker. If you’re building a web application, and you
need an assembly deployed but don’t want it referenced and don’t want
it checked into the bin directory, you can simply add this folder
yourself and put your own assemblies in here.

Can not remove Default.aspx from Asp.net MVC 3 Application

I am working on a project that started out using ASP.Net MVC 1 and has since been upgraded to ASP.Net MVC 3. It is my understanding that if I am running my ASP.NET MVC 3 app on IIS 7 using the integrated pipeline that I no longer need the Default.aspx file. However after I have removed the file from the project and physically deleted it I get the following error every time I try to compile in Release mode:
Description: Could not load type 'ProjectName.Default'.
File: Default.Aspx
I have verified that there is no instance of ProjectName.Default or Default.aspx in my project file. I have even done a grep search in all of my files in the project for any mention those names and still have found nothing. What do I need to do to be able to remove Default.aspx from my ASP.Net MVC 3 app and get it to compile in release mode. It compiles just fine in Debug mode by the way.
From the debugging listed here you probably had a cached version of your compiled code. While Visual Studio builds the code behind files into a single DLL, ASP.NET compiles each aspx file into a DLL as well (depending on how you configure it, there can be variations on this). These DLLs are located at %WINDIR%\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files note that this directory is sensitive to .Net version, could be in 2.0 or 4.0, it is also in some way dependent on bit-ness, as there is a similar directory in Framework64.
I tried to clean my solution, delete the project temp files, remove all the leftover crud I could think of. Unfortunately none of this worked so I had to take the brute force approach and checkout a new copy of my project. After doing this I no longer had the error occur when building the new copy that had Default.aspx removed. Unfortunately this solution did not provide me any insight into what leftover file Visual Studio was holding onto.

Publishing my ASP.NET MVC project doesn't publish all necessary files

I'm using the publishing wizard and it published all of the necessary files except for my Controllers folder. I was under the assumption that I need a controller.
I have navigated to Package/Publish Web setting, do I need to tweak anything in here? I'm guessing this isn't set up properly out of the box. If I change the drop down to publish all files in this folder/solution will it try to upload all the referenced DLLs that don't need to be copied to the server?
In ASP.NET web projects, including MVC projects, .cs files (controllers in this case) are compiled into the /bin/[your.project].dll assembly when you do a Build or Publish.
So you don't need to publish/copy .cs files.
The controller and model code is compiled into the web site dll. The views are deployed in their folders.

Resources