将 C# 项目引用放置在子文件夹中
我有一个包含多个项目的解决方案,所有项目都输出 dll(当然主应用程序除外)。对于所有引用,复制本地设置为 true,一切都很好,dll 与 exe 位于同一目录中。
我的问题是这很丑。我想将所有 dll 放在一个子文件夹中(准确地说,实际上是两个子文件夹)。如何在 Visual Studio 2008 中执行此操作?
我发现了一些看起来相似的问题,但我找不到我知道必须存在的简单答案。
编辑:更清楚地说,我想知道如何使程序集加载器在操作目录之外的其他地方查找引用。用户将与目录中的一些其他文件进行交互,对他们来说,混乱越少越好。
编辑 2:我还想避免使用 GAC。该应用程序需要是独立的。
I have a solution with multiple projects that all output dlls (except for the main application of course). Copy local is set to true for all of the references and everything is fine and dandy with dlls in the same directory as the exe.
My problem is that this is ugly. I'd like to put all the dll's in a subfolder (actually two subfolders down to be precise). How can I do this in Visual Studio 2008?
I've found a few questions that seem similar but I couldn't find the simple answer that I know has to exist.
EDIT: To be clearer, I want to know how to make the assembly loader look for references somewhere besides the operating directory. Users will be interacting with some of the other files in the directory, and the less clutter there is for them the better.
EDIT 2: I also want to avoid using the GAC. The application needs to be self contained.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您尝试过 AppDomain 命名空间吗?
AppDomain.CurrentDomain.AppendPrivatePath
http://www.vcskicks.com/csharp_ assembly.php
Have you tried the AppDomain namespace?
AppDomain.CurrentDomain.AppendPrivatePath
http://www.vcskicks.com/csharp_assembly.php
或者
AssemblyResolve
Or
AssemblyResolve
使用 app.config
元素指示 .NET 运行时在子文件夹中查找以查找其他程序集。请参阅此处 。Use the app.config
<probing>
element to instruct the .NET Runtime to look in the subfolders to locate additional assemblies. See here.您不能将这些引用放入子文件夹中。因为它们不会被应用程序的运行时“看到”。
首先放置它们的位置是调试目录,然后是全局程序集缓存(又名 GAC)。请注意,您在“添加引用”对话框的 (.Net) 选项卡中看到的实际上是 GAC 目录中的引用。
注意:如果您使用 TFS 作为后端源代码管理,请注意,在执行签入时,引用不会复制到源代码控制存储库,而是必须手动复制它们。
You can't put those references in a subfolder. Since they will not be "seen" by your application's run-time.
The first place to put them is in your debug directory then in the Global Assembly Cache (aka GAC). Note that what you see in the (.Net) tab in
Add Reference
dialog is actually the references in the GAC directory.Note: If you use TFS as a backend source control, take notice that reference are not copied to the source control repository when you perform a check-in, rather you have to copy them manually.
我刚刚发表了一篇文章,详细解释了所有这些。
通过 .NET 程序集和 Visual Studio 项目对代码库进行分区
以下是本文得出的指导原则:
I just publish an article that explain all these with details.
Partitioning Your Code Base Through .NET Assemblies and Visual Studio Project
Here are the resulting guidelines of the article: