24

I've been doing .NET development for about a year, but I still don't know what the purpose of the <assemblies> section is.

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?

Esteban Araya
  • 29,284
  • 24
  • 107
  • 141
kevin
  • 13,559
  • 30
  • 79
  • 104

2 Answers2

25

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; 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. During this compilation process, ASP.NET needs to link in your dependencies in order to compile your application. By default, ASP.NET will scan the bin folder and the .NET framework installation directory to find the assemblies specified.

Can the references be deleted in the 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; if it doesn't, don't remove it.

Hope this gives you enough info to get moving in the right direction.

Esteban Araya
  • 29,284
  • 24
  • 107
  • 141
4

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.

This is used quite commonly in ASP.Net MVC.

Phil Haack has an example of this: http://haacked.com/archive/2006/11/14/register_custom_controls_in_web.config.aspx

Russ Clarke
  • 17,511
  • 4
  • 41
  • 45
  • Russ C >> Thanks. Sometimes I got the error pointing to this assemblies. So can i delete it ? – kevin May 10 '11 at 02:49
  • It depends which assembly is showing the error, and indeed what is showing the error ? If you're using resharper, if often shows problems in config files; in which case I tend to disable analysis of .config files. If you're not - what is the specific error ? – Russ Clarke May 10 '11 at 02:52
  • Russ C>> I got some errors pointing to some assemblies one week ago. I forget the exact error and somehow we manage to solve it. So I wonder whether I can delete it. Thanks for your reply !! – kevin May 10 '11 at 02:56
  • 1
    Hmm, the problem is, you won't know if you needed that reference until the CLR attempts to use it. If you're sure it wasn't a reference to a .net assemblie that comes with the framework, you may be safe to remove it; However, you might only see the error if you try to compile your app with web.config open - if this is the case, I'd just leave it be. – Russ Clarke May 10 '11 at 03:00
  • Russ C >> btw, how does it show up in my web.config ? It autogenerates when I compile my webapp for the first time ? – kevin May 10 '11 at 03:07
  • How does what appear, sorry ? – Russ Clarke May 10 '11 at 03:08
  • I think there's a BuildProvider in ASP.NET that puts in the common system ones; or the ASP.Net template in Visual Studio does it. In honesty, I've never checked properly, I've only added them there when I'm doing MVC development. – Russ Clarke May 10 '11 at 03:20