对于Web项目,Asp.Net仅检测aspx中的更改,而不能检测cs文件中的更改 [英] With Web projects Asp.Net only detects changes in aspx, but not cs files

查看:72
本文介绍了对于Web项目,Asp.Net仅检测aspx中的更改,而不能检测cs文件中的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


Q1-Asp.Net能够检测到您何时更改了原始文件,并在下一个请求到达时自动重新编译应用程序

Q1 - Asp.Net is able to detect when you change the original files and automatically recompilles the application when next request arrives


A)但是看来,尽管使用Web站点,Asp.Net能够检测到更改,无论它们是在代码隐藏文件(.cs)还是在aspx文件中发生,而对于Web项目,Asp.Net只能检测到更改发生在aspx文件中,但无法检测到.cs文件中的更改!为什么会这样?

A) But it appears that while with Web sites Asp.Net is able to detect changes, regardless of whether they happen in code-behind file (.cs) or in aspx file, with Web projects Asp.Net only detects changes that happen inside aspx file, but it doesn’t detect changes inside .cs files! Why is that?


B)Asp.Net还可以检测是否有任何新的aspx或cs文件添加到网站.但是,会在下一个请求时仅编译添加的文件,还是会重新编译应用程序的所有文件?

B) Asp.Net also detects if any new aspx or cs files were added to the website. But, will it upon the next request compile just the added files, or will it recompile all of app’s files?


C)如果Web服务器上的应用程序包含多个aspx文件,其中一些是由web项目创建的(因此,它们在文件后面的代码位于单个程序集中),而其他aspx文件是通过网站项目创建的,那么Asp.Net怎么了?能够找出特定的aspx文件是否在Bin目录中的程序集中包含背后的代码?

C) If an application on a web server contains several aspx files, some created by web project ( and thus their code behind files are inside single assembly ) while other aspx files were created via a website project, how is Asp.Net able to figure out whether particular aspx file has code behind contained within an assembly located in Bin directory?


第二季度 "Codebehind属性仅由Visual Studio Web窗体设计器使用.该属性在运行时不使用."

Q2 "Codebehind attribute is used only by the Visual Studio Web Forms Designer. The attribute is not used at run time."

  • 我假设由于所有.cs文件都被编译为单个程序集,因此在运行时未使用CodeBehind属性,因此只要aspx通过以下方式告诉类名,VS便可以毫无问题地找到该类继承属性吗?!

  • I assume CodeBehind attribute is not used at runtime due to the fact that all .cs files are compiled into single assembly, and thus VS has no problem locating a class as long as aspx tells the name of the class via Inherits attribute?!

另一方面,模型后面的Asp.Net代码确实需要src属性,因为在这里,cs文件被编译为单独的程序集,因此asp.net需要知道CodeFile属性指定的文件名称,因此它可以以某种方式找出此文件编译到的程序集的名称?

On the other hand, Asp.Net code behind model does need src attribute, because here cs files get compiled into separate assemblies and thus asp.net needs to know the name of the file specified by CodeFile attribute, so it can somehow figure out the name of the assembly into which this file compiled?


感谢

推荐答案

ASP.NET仅在找不到在现有程序集中完成ASPX编译所需的类型的情况下,才在文件后面查找代码.仅当在为ASPX文件构建临时程序集时需要CS文件背后的代码时,才会创建依赖项.

ASP.NET only looks for a code behind file if it can't find the type it needs to complete the compilation of a ASPX in the existing assemblies. A dependancy on the code behind cs file is only created if it was needed when building the temporary assembly for the ASPX file.

因此,在一个Web项目中,所有cs文件后面的代码都被编译到一个程序集中,因此ASPX的临时程序集的编译不需要cs后面的代码,因为所需的类型已经存在于pre中.组装的装配体.因此,在临时程序集和cs文件之间不会创建依赖关系,因此更改cs文件不会使现有的临时程序集无效.请注意,在部署中,cs文件甚至都不存在.

Therefore where in a web project all the codebehind cs files are compiled into a single assembly the compilation of a temporary assembly for the ASPX does not require the code behind cs, since the type(s) needed are already present in the pre-built assembly. Hence no dependancy is created between the temporary assembly and the cs file so changing the cs file does not invalidate the existing temporary assembly. Note in deployment the cs files won't even be present.

在网站上,没有预编译的程序集,其中包含所有代码后置类型,因此需要代码后置文件来完成ASPX的临时程序集,从而增加了对cs文件的依赖到那个临时集会.因此,对cs文件的任何更改都会使临时程序集无效.

In a web site there is no pre-built assembly containing all the types in code-behind, hence the code-behind file is required to complete the temporary assembly for an ASPX, in turn a dependancy on the cs file is added to that temporary assembly. Hence any change to the cs file invalidates the temporary assembly.

这篇关于对于Web项目,Asp.Net仅检测aspx中的更改,而不能检测cs文件中的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆