简体   繁体   English

Web.config中的程序集

[英]Assemblies in Web.config

I've been doing .NET development for about a year, but I still don't know what the purpose of the <assemblies> section is. 我已经进行了大约一年的.NET开发,但我仍然不知道<assemblies>部分的用途是什么。

What is the section's purpose? 该部分的目的是什么? Can I delete the assemblies specified in there? 我可以删除那里指定的程序集吗? I asked some senior developers in my team but they just told me to ignore it. 我问过团队中的一些高级开发人员,但他们只是告诉我要忽略它。 Can someone give me a good explanation on it? 有人可以给我一个很好的解释吗?

What is the purpose of the assemblies section? 装配部分的目的是什么?

The <assemblies> element in an ASP.NET application defines the assemblies that are used during compilation of an application; ASP.NET应用程序中的<assemblies>元素定义在编译应用程序期间使用的程序集; the assemblies on this list should be the ones you depend on and are thus required for your code to compile. 此列表上的程序集应该是您依赖的程序集,因此需要编译代码。

This section is necessary because ASP.NET will compile the application the first time a user requests a resource from your application. 此部分是必需的,因为ASP.NET将在用户第一次从您的应用程序请求资源时编译应用程序。 During this compilation process, ASP.NET needs to link in your dependencies in order to compile your application. 在此编译过程中,ASP.NET需要链接您的依赖项以编译您的应用程序。 By default, ASP.NET will scan the bin folder and the .NET framework installation directory to find the assemblies specified. 默认情况下,ASP.NET将扫描bin文件夹和.NET框架安装目录以查找指定的程序集。

Can the references be deleted in the Web.config? 可以在Web.config中删除引用吗?

It depends; 这取决于; if you're not using the dependency, sure, you can delete it. 如果你没有使用依赖项,当然可以删除它。 Most likely, you'll be able to remove some of them, but not all of them. 最有可能的是,你将能够删除其中的一些,但不是全部。

To find out which dependencies you can remove, do the following: 要找出可以删除的依赖项,请执行以下操作:

  1. Remove the reference from your project. 从项目中删除引用。
  2. Compile your application. 编译您的应用程序。
  3. If your application still compiles, go ahead and remove it from your Web.config; 如果您的应用程序仍在编译,请继续将其从Web.config中删除; if it doesn't, don't remove it. 如果没有,请不要删除它。

Hope this gives you enough info to get moving in the right direction. 希望这能为您提供足够的信息以便朝着正确的方向前进。

It's worth noting that this sub-key of Web.Config can be used to reference common assemblies in your webform app, so you don't have to include a reference in every page or control that uses the assembly. 值得注意的是,Web.Config的这个子键可用于引用webform应用程序中的常见程序集,因此您不必在每个使用程序集的页面或控件中包含引用。

This is used quite commonly in ASP.Net MVC. 这在ASP.Net MVC中非常常用。

Phil Haack has an example of this: http://haacked.com/archive/2006/11/14/register_custom_controls_in_web.config.aspx Phil Haack就是一个例子: http//haacked.com/archive/2006/11/14/register_custom_controls_in_web.config.aspx

有一些很好的探索。

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

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