Automatic reference of class files inside App_Code vs reference of class files outside App_Code

我的梦境 提交于 2019-12-24 09:09:42

问题


all questions refer to Web site projects.


1) Why are file classes inside App_Code folder automatically referenced by the rest of application, while file classes created outside App_Code aren’t?


2) I don’t know much about compilation, but why do we need to explicitly reference class files created outside App_Code? Because those files will be compiled into dlls created and named by programmer and as such VS doesn’t know what the names of these dlls and so can’t automatically reference these dlls?

3) Files outside App_Code by default don’t get automatically compiled? But why not?


thanx


回答1:


Sounds to me like you are expecting Web Application behaviour from a Web Site "project".

In a Web site each ASPX/ASHX file (outside of the App_Code) is considered content. At any point you may wish to simply publish a few of the files to the web site. Hence compiling all them at once into a single assembly is not desirable.

With a Web Application you don't normally publish just a few files, you complete a phase of the application, compile it all together and then publish.

You seem to indicate you have "classes" declared outside of App_Code? Where would they be if not in their own dll project? If in a dll project then you need to create a project reference to in the Web Site properties.




回答2:


The App_Code folder is mainly used with Website projects whereas with Web Application Projects you would typically reference the library class. App_Code is supposed to work with the WAP model but I find that it often doesn't play nice.

You can read more about it here (check the reference links): http://www.codersbarn.com/post/2008/06/01/ASPNET-Web-Site-versus-Web-Application-Project.aspx



来源:https://stackoverflow.com/questions/1336811/automatic-reference-of-class-files-inside-app-code-vs-reference-of-class-files-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!