问题
Could anyone point out the advantage of using assemblies, in the 'context' of ASP.NET.
As I understand it, assemblies run as executables, have a single entry point, and can be run inside an application domain, but I've found very few suitable examples on the web.
回答1:
An assembly is not just an executable... an assembly is essentially a .NET library that may have an executable entry point...
Wikipedia article with description of assemblies First paragraph:
In the Microsoft .NET framework, an assembly is a partially compiled code library for use in deployment, versioning and security. There are two types: process assemblies (EXE) and library assemblies (DLL). A process assembly represents a process which will use classes defined in library assemblies. .NET assemblies contain code in CIL, which is usually generated from .NET languages, and then compiled into machine language at runtime by the CLR just-in-time compiler. An assembly can consist of one or more files. Code files are called modules. An assembly can contain more than one code module and since it is possible to use different languages to create code modules it is technically possible to use several different languages to create an assembly. Visual Studio however does not support using different languages in one assembly.
回答2:
Assemblies are not always executables. Most of people will define them as a collection of class modules presented as a single DLL or EXE file. The closest thing to them are the Java JARs.
They have metadata (see http://en.wikipedia.org/wiki/.NET_metadata) which contains a bunch of information such as
- version
- methods and types
They also have a manifest which is part of this metadata (see http://msdn.microsoft.com/en-us/library/1w45z383.aspx).
You can register assemblies into the Global Assembly Cache (GAC) (see http://en.wikipedia.org/wiki/Global_Assembly_Cache), and you will make them available to all the other programs on the machine. (when in Visual Studio, you use "Add references", and browse the .Net tab, you are watching a list of assemblies in the GAC).
You do not have to add them in the GAC, you can directly reference a private assembly, but registering them in the GAC make them globally available on the computer.
This link contains sensible information about assemblies:
- http://www.akadia.com/services/dotnet_assemblies.html#Assemblies
回答3:
This question does not make a lot of sense. Assemblies contain class libraries, it is not an either or kind of thing. Even if you only have aspx files, the first time someone accesses a page, ASP.Net compiles it into a class and then an assembly on the fly.
回答4:
@maxp, are you asking if it is better to include the class as a .cs file in the project or as a compiled .dll in the references?
I used to keep common functions in class files (.cs) and just include them in what ever project I was working on. The classes live under source control so I would just make sure I got the latest version anytime I created a new project. However lately, I have begun to compile them and register them in the GAC. This helps reduce the headache of not every really knowing which version of the class is included in a given project. If you make a change to the class, just re-register it with the GAC and all your apps are updated and using the same version.
The only real drawback I have encountered is if you are trying to debug and step through the logic. Just make sure your classes are solid before you compile and place in GAC.
Hope this helps answer your question.
来源:https://stackoverflow.com/questions/1888402/assemblies-vs-class-libraries-net