简体   繁体   English

ASP.net网站引用依赖于未编译代码的代码文件

[英]ASP.net Web Site referencing code files with dependencies on non-compiled code

I have a website that is not utilizing the App_Code folder for jit compiling code files (that is what App_code is for, right?). 我有一个网站没有将App_Code文件夹用于jit编译代码文件(这就是App_code的目的,对吧?)。 Instead developers have to either cram all the necessary classes that they need for a page into the code file, or into an individual .cs file that gets and Assembly Directive src on the page (this is because of dependencies between the source files). 取而代之的是,开发人员必须将页面所需的所有必需类都填充到代码文件中,或将单个.cs文件填充到页面中并带有Assembly Directive src的单个.cs文件中(这是由于源文件之间的依赖性)。

Is there any way for classes with dependencies on each other to be placed in separate files? 有没有办法将相互依赖的类放在单独的文件中?

For instance Presenter.cs has a dependency on Model.cs. 例如Presenter.cs依赖于Model.cs。 I would like to just add an assembly directive to my page for Presenter.cs, and make it happy. 我只想在Presenter.cs的页面上添加一个汇编指令,并使其高兴。 But since this does not compile Model.cs, it doesn't work. 但是由于这不能编译Model.cs,所以它不起作用。 Adding Assembly references for both code files also does not work. 为两个代码文件添加程序集引用也不起作用。

Is there a mechanism that I am missing? 我是否缺少一种机制?

EDIT: I think the answer is that the App_Code folder is exactly created for this task and that there is no other/better way to do it. 编辑:我认为答案是App_Code文件夹是完全为此任务创建的,没有其他/更好的方法来做到这一点。

When you say "CodeBehind" are you actually referring to "CodeFile"? 当您说“ CodeBehind”时,您实际上是在指“ CodeFile”吗? (One of the many reasons I'm not a fan of "ASP.NET Websites" and prefer MVC). (我不喜欢“ ASP.NET网站”并且更喜欢MVC的众多原因之一)。

AFAIK, the ASP.NET runtime compiles all of the App_Code files together into their own assembly, however code in each page's CodeFile (not their CodeBehind) can only reference this anonymous assembly and not each others' code. AFAIK,ASP.NET运行时将所有App_Code文件一起编译到它们自己的程序集中,但是每个页面的CodeFile中的代码(不是它们的CodeBehind)只能引用此匿名程序集,而不能引用彼此的代码。

Can you clarify what you mean by "page assembly reference"? 您能否阐明“页面汇编参考”的含义? Are you doing <%@ Assembly %> or do you mean a namespace import <%@ Import %> (because as I said, a lot of the code is compiled into an anonymous assembly). 您是在执行<%@ Assembly %>还是在名称空间中导入<%@ Import %> (因为正如我所说,很多代码都被编译成匿名程序集)。

I suggest you just move the common code and classes to *.cs files within App_Code. 我建议您将通用代码和类移至App_Code中的* .cs文件中。 It should just work. 它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM