Chapter 12. Assemblies and Deployment

So far in this book, I’ve used the term component to describe either a library or an executable. It’s now time to look more closely at exactly what that means. In .NET the smallest unit of deployment for a software component is called an assembly, and it is typically a .dll file. Assemblies are an important aspect of the type system, because each type is identified not just by its name and namespace but also by its containing assembly. Assemblies provide a kind of encapsulation that operates at a larger scale than individual types, thanks to the internal accessibility specifier, which works at the assembly level.

.NET assemblies can’t run on their own—they rely on the .NET runtime, and we have a few options for ensuring that a suitable runtime is available when we deploy our applications. The runtime provides an assembly loader, which automatically finds and loads the assemblies a program needs. To ensure that the loader can find the right components, assemblies have structured names that include version information, and they can optionally contain a globally unique element to prevent ambiguity.

Most of the C# project types in Visual Studio’s “Create a new project” dialog produce a single assembly as their main output, as do most of the project templates available from the command line with dotnet new. When you build a project, it will often put additional files in the output folder too, such as copies of any assemblies that your code relies ...

Get Programming C# 12 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.