将单独的类编译成单独的dll [英] Compiling separate classes into separate dlls

查看:94
本文介绍了将单独的类编译成单独的dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,当发现新的DLL放入文件夹时会动态加载DLL.这些DLL假定每个DLL具有一个类,并处理一项任务.在Visual Studio 2010解决方案中,我将所有.cs文件都放在一个DLL项目下.

我想做的是将.csproj文件更改为在构建时输出多个DLL,而不只是一个DLL.我可以将.cs文件移动到单独的项目中,但这似乎不必要地多余.有办法做到吗?

I have a project that dynamically loads DLLs when it discovers new ones were dropped into a folder. These DLLs are supposed to have one class per DLL, and handle one task. In the Visual Studio 2010 solution, I have all the .cs files under one DLL project.

What I would like to do is change the .csproj file to output several DLLs at build time, instead of just one DLL. I could move the .cs files into separate projects, but that seems unnecessarily redundant. Is there a way to do this?

推荐答案

使用以下命令行:
Use the following command line :
for %%1 in (*.cs) do csc /target:library %%1


,例如,您可以创建一个单独的项目控制台应用程序,可以从目标项目文件夹中读取所有.cs文件并从中生成单独的dll
http://stackoverflow.com/questions/604501/generating-dll-assembly-动态运行时 [ ^ ]

http://support.microsoft.com/kb/304655 [
you can create a seperate project for example console application and can read all .cs files from target project folder and generate separate dlls from it
http://stackoverflow.com/questions/604501/generating-dll-assembly-dynamically-at-run-time[^]

http://support.microsoft.com/kb/304655[^]

Now you have 2 options to build dlls
1 - you run console application each time you want to generate all dlls
2 - In Visual Studio > Project properties of dll project > Build Events Tab > Post/Pre Build events settings you can add console app''s exe to run now each time you build your dll library''s project after building it the console app''s exe will run and create seperate dlls for you.

The only thing i think tricky is how will you resolve dependency between different classes when you have multiple dlls.

Hope this idea will help


这篇关于将单独的类编译成单独的dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆