.net 根命名空间和程序集名称之间的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/314101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between Root Namespace and Assembly Name
提问by MOZILLA
What's the difference between the two?
两者有什么区别?
回答by Dafydd Giddins
Assuming that you are talking about .NET (with relation to Visual Studio) then the root namespace is what each class you create in a visual studio project will become part of. It is also the base for any sub-namespaces that are automatically assigned when you create a class inside of a project folder.
假设您谈论的是 .NET(与 Visual Studio 相关),那么根命名空间就是您在 Visual Studio 项目中创建的每个类都将成为其中的一部分。它也是在项目文件夹中创建类时自动分配的任何子命名空间的基础。
So with a base namespace of ACMECorp.Bombs all of your classes would become part of the ACMECorp.Bombs namespace so the class GravityBomb would have a full name of ACMECorp.Bombs.GravityBomb. A class called FlyingBomb created in a project folder called GuidedBombs would have a full type name of ACMECorp.Bombs.GuidedBombs.FlyingBomb.
因此,对于 ACMECorp.Bombs 的基本命名空间,您的所有类都将成为 ACMECorp.Bombs 命名空间的一部分,因此 GravityBomb 类的全名将是 ACMECorp.Bombs.GravityBomb。在名为 GuidedBombs 的项目文件夹中创建的名为 FlyingBomb 的类的完整类型名称为 ACMECorp.Bombs.GuidedBombs.FlyingBomb。
The Assembly name is simply the name of the compiled file that your code will be compiled to as either an executable or library etc...
程序集名称只是您的代码将被编译为可执行文件或库等的已编译文件的名称...
A question that I often see on this is should your assembly name be the same as the root namespace and also be the same as your project name(again in visual studio). I used to be of the mind set that you should have a project name the same as the assembly name the same as the root namespace just as is the default with visual studio. However if you need to do some major refactoring and renaming this can become a pain in the bum, especially if you are using source control (as you then should start renaming the project folders).
我经常看到的一个问题是你的程序集名称是否应该与根命名空间相同,也应该与你的项目名称相同(再次在 Visual Studio 中)。我曾经认为你应该有一个与程序集名称相同的项目名称与根名称空间相同,就像 Visual Studio 的默认名称一样。但是,如果您需要进行一些重大的重构和重命名,这可能会成为一个麻烦事,尤其是在您使用源代码管理时(因为您应该开始重命名项目文件夹)。
My suggestionwould be that your project name is simply a descriptive name of the contents of the project. Your assembly name should consist of the technology area and component description, or company name and technology area (depending on your preferance), and your root namespace should be as described by the Microsoft naming standards so:
我的建议是您的项目名称只是项目内容的描述性名称。您的程序集名称应包含技术领域和组件描述,或公司名称和技术领域(取决于您的偏好),并且您的根命名空间应如 Microsoft 命名标准所描述的那样:
Project: Biometric Device Access
Assembly: BiometricFramework.DeviceAccess.dll
Namespace: ACME.BiometricFramework.DeviceAccess
项目:生物识别设备访问
程序集:BiometricFramework.DeviceAccess.dll
命名空间:ACME.BiometricFramework.DeviceAccess
Some reference material for you:
给你一些参考资料:
http://blogs.msdn.com/brada/archive/2003/04/19/49992.aspx
http://blogs.msdn.com/brada/archive/2003/04/19/49992.aspx
http://msdn.microsoft.com/en-us/library/ms229026.aspx
http://msdn.microsoft.com/en-us/library/ms229026.aspx

