如何获取类库的当前目录?
我一直在四处寻找,但没有找到解决此问题的方法:我想创建一个类库,该类库在名为 Configuration 的子目录下有一个配置文件。 我希望该类库部署在任何地方,并且希望它通过知道自己的位置来找到其配置文件。
之前尝试使用 Assembly.GetExecutingAssembly().Location
失败。
它将返回临时位置,例如
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\7c00e0a3\38789d63\ assembly\dl3\9c0a23ff\18fb5feb_6ac3c901
而不是所需的
bin/Configuration
路径。
那么:
- 类库可以知道它自己在磁盘上的位置吗?
- 我将如何编写此功能的测试脚本,因为目录似乎根据您运行应用程序的方式而变化(在 VS 内调试、在 IIS 上部署等)
I've been looking around but I have not found a solution for this problem: I want to create a class library that has a configuration file under a sub-directory called Configuration. I want that class library to be deployed anywhere and I want it to find its configuration files by knowing its own location.
Previous attempts with Assembly.GetExecutingAssembly().Location
did not work.
It would return temp locations such as
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\7c00e0a3\38789d63\assembly\dl3\9c0a23ff\18fb5feb_6ac3c901
instead of the desired
bin/Configuration
path.
So:
- Can a class library be aware of its own location on disk?
- How would I go about witting test scripts for this functionality since it seems that directories change based on how you run the app (debugging inside VS, deploying on IIS, etc)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该有效 -
This should work -
下面的代码帮助我获取类库文件中图像文件夹的物理路径。
我希望,它会对某人有所帮助。
The below code worked for me to get the physical path of the Images folder in-class library file.
I hope, it will help someone.