如何为类库中的每个类文件编译单独的程序集
我有一个包含很多类的类库,我想将每个类编译成自己的程序集。这可能吗?
I have a class library with a bunch of classes and I would like to compile each of my classes into its own assembly. Is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是可能的。当您为 Visual Studio 中存在的每个项目编译解决方案时,会创建一个单独的程序集,因此您只需为每个类创建一个项目即可获得所需的内容。
话虽如此,我不确定每个班级举行一次集会是一件好事。在运行时加载程序集的成本很高,并且在设计时管理它们也需要一些努力。您愿意详细说明为什么您需要这样的东西吗?
It is possible. A separate assembly is created when you compile your solution for each project that exists in Visual Studio, so you only need to create a project per class to obtain what you want.
Having said that, I am not sure that having one assembly per class is a good thing to do. Loading assemblies at run-time is expensive, and managing them at design-time requires some effort too. Would you care to elaborate on why you need such a thing?
您可能需要做一些 msbuild 体操,但这可能会让您开始上路。
Stack Overflow - Visual Studio One 项目有多个 dll 作为输出?< /a>
You might have to do some msbuild gymnastics but this might get you started on your way.
Stack Overflow - Visual studio one project with several dlls as output?
我不得不猜测你真正的问题是“它可以自动完成吗?”不,您必须为每个程序集创建一个项目。这对维护和部署来说是一场噩梦,而且没有任何显而易见的优势。
I would have to guess your real question is "can it be done automatically?" No, you have to create a project for each assembly. Quite a maintenance and deployment nightmare with no easily conceivable advantages.