是否可以在“ASP.NET Web应用程序”中进行动态编译? [英] Is dynamic compilation in a 'ASP.NET Web Application' possible?
问题描述
我可以以某种方式利用Web应用程序项目中的 App_code
文件夹来即时编译代码吗?这对插件来说非常棒Rob Conery最近在一个ASP.NET MVC应用程序的MIX 09演讲中展示了它的用途。我试图在网络应用程序中执行相同操作,但是我无法从任何其他地方访问 App_Code
下的类。但是如果Rob能够在MVC应用程序中做到这一点,那么在Web应用程序中也应该是可行的。所有的ASP.NET MVC是一个ASP.NET Web应用程序的封面。
Can I somehow utilize the App_code
folder in a web application project to compile code on the fly? It'd be great for plugins. Recently Rob Conery demonstrated its use in his talk at MIX 09 in a ASP.NET MVC app. I tried to do the same in a web app but I can't access the classes under App_Code
from anywhere else. But if Rob was able to do it in an MVC app, it should be doable in a web application too. After all ASP.NET MVC IS a ASP.NET Web Application under the covers.
推荐答案
如果你添加一个代码文件到App_Code文件夹,它应该被编译并可以从一个控件的代码隐藏文件或App_Code文件中的另一个代码文件。
If you add a code file to the App_Code folder, it should be compiled and available from a code-behind file for a control, or another code file in the App_Code file.
我不认为你'可以直接从编译的程序集中访问它,因为编译器将无法在编译时找到该引用。
I don't think you'll be able to access it directly from a compiled assembly, since the compiler won't be able to find that reference at compile time.
您还需要意识到App_Code被编译成与代码隐藏代码不同的程序集,因此您无法访问 内部
代码跨不同的程序集。
You'll also need to be aware that App_Code is compiled into a different assembly than your code-behind code, so you can't access internal
code across the different assemblies.
这篇关于是否可以在“ASP.NET Web应用程序”中进行动态编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!