开发者

Create .Net library with sub-assemblies

开发者 https://www.devze.com 2023-03-27 06:36 出处:网络
How can I create a dll in .NET that has sub-assemblies? For example, if I have a project \"MyUtilities\", I\'d like to create a sub-assembly \"MyUtilities.EmailUtilities\" with classes specific to em

How can I create a dll in .NET that has sub-assemblies?

For example, if I have a project "MyUtilities", I'd like to create a sub-assembly "MyUtilities.EmailUtilities" with classes specific to emailing. Then, in a new project, when I add a reference to the compiled dll of MyUtilities, I could access the EmailUtilities classes using code like:

MyUtilities.EmailUtilities.EmailBlaster eBlaster = new MyUtilities.EmailUtilities.EmailBlaster开发者_如何学Python


What you want is a namespace.


You should make a single ordinary project with a subfolder called EmailUtilities.
This will create a separate namespace containing those classes.


You're mixing up namespaces and assemblies. They have nothing to do with each other. Namespaces can span across multiple assemblies, and assemblies can have multiple namespaces.

What you're describing is just sub-namespaces, which can be done all in code.

Either:

namespace MyUtilities
{
    namespace EmailUtilities
    {
         // Your code here
    }
}

Or, more commonly:

namespace MyUtilities.EmailUtilities
{
    // Your code here
}


You cannot create sub-assemblies in .NET, at least not the way you are thinking about. They only thing remotely close is satellite assemblies, but that is not what you want. What you should do is organize your classes into separate namespaces. Note that the namespaces can be nested.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号