【发布时间】:2010-01-13 18:04:14
【问题描述】:
我有一个名为“VirusScanManager”的类库,其中包含一个名为“Lib”的文件夹。此文件夹包含命令行扫描程序 exe 和支持文件。所有这些文件都将“构建操作”设置为“内容”,将“复制到输出目录”设置为“始终复制”。
在库中,我使用以下行获取文件夹的路径:
string virusCheckFolder
= Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Lib");
我有一个引用 VirusScanManager 的测试类库。运行测试时,virusCheckFolder 设置为
C:\...\Projects\WebSiteMobileAdmin\Tests\bin\Debug\Lib
这是有效的,因为文件被复制到那里。
我还有一个引用 VirusScanManager 的 BusinessLogicLayer 类库。当我运行我的网站时,virusCheckFolder 设置为
C:\...\WebSites\WebSiteMobileAdmin\Lib
这不起作用,因为文件实际上已复制到
C:\...\Projects\WebSiteMobileAdmin\BusinessLogic\bin\Debug\Lib
然后我按照 Beaner 的建议尝试了反射:
string pathToDLL = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", ""));
string virusCheckFolder = Path.Combine(pathToDLL, "Lib");
这给了我
C:\...\WebSites\WebSiteMobileAdmin\Bin\Lib
但是这个文件夹不存在。 我在 WebsiteMobileAdmin 中有对 BusinessLogicLayer 的引用,在 BusinessLogicLayer 中有对 VirusScanManager 的引用。看来,当我进行构建时,会在 BusinessLogicLayer\bin\debug 和 WebsiteMobileAdmin\bin 中创建 dll,但 lib 文件夹仅复制到 BusinessLogicLayer\bin\debug。
那么,有没有办法获得适用于这两种情况的内部库的路径?
【问题讨论】: