Out of curiosity, in my c# project/solution which assembly will each namespace go into? How does it decide which namespace to put into which assembly?
Edit: Was just a bit confused, I thought that there was some kind of correlation between which namespace go in which assembly.
which assembly will each namespace go into?
There is ZERO correlation between namespace and assembly.
The compiled class goes into the assembly created by the project - every project one assembly. Namespaces can be used on many assemblies and there is simply ZERO correlation technically, though CONVENTION says you keep correlated namespaces in one assembly - the compiler does not care.
At the end, TYPES go into an assembly, and TYPES have a namespace - but nothing in the build process cares as decision where it goes.
Each project usually builds one assembly, regardless of namespaces. So there isn't a direct relationship between namespaces and assemblies, since you can declare multiple namespaces in a single project, and can declare the same namespace across different assemblies.
However, the usual recommendation (ht CodeCaster) is to name the projects, their output assemblies, and their namespaces consistently, so that it's clear which namespace comes from which assembly. So if you make a project named MyCompany.MyApp.csproj
, it by default creates an assembly named MyCompany.MyApp.dll
(or .exe
), and new files you create will be in the MyCompany.MyApp
namespace. You can have child namespaces within your project, typically corresponding to the folder structure in the project, eg folder Section
contains types in the namespace MyCompany.MyApp.Section
. But again, this is all convention - you can change the namespace
directives in each file to do something different.
Keeping it very simple. Assembly is phsical grouping but NameSpace is logical grouping. Assembly can have more namespaces.
System.Data
is a namespace, System.Data.DLL
is an assembly
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.