如何在.config文件中指定相对于该文件的路径? [英] How to specify path in .config file relative to the file?
问题描述
我使用的一个应用程序解释.NET .config
文件.我添加了一行,指定了所需证书的路径
An app I use interprets a .NET .config
file. I added a line specifying the path to a certificate it needs
<add key="Certificate" value="..\certificate.abc"/>
但是,我发现该应用程序只能在其.exe
和.config
所在的确切文件夹中运行时才能运行.如果从另一个文件夹运行,它将失败,因为它会在相对于工作目录展开的../
中查找证书.
However, I found the app only works when run from the exact folder its .exe
and .config
reside. If run from another folder, it fails, because it looks for the certificate at ../
expanded relative to the working directory.
我应该在配置文件中写些什么,以确保相对于配置文件(工作目录)相对于配置文件扩展了..\certificate.abc
路径.
What should I write in the config file, to make sure the path is ..\certificate.abc
expanded relative to the config file rather the working directory?
我不能更改应用程序(不是我的),只能更改配置文件.
I can't change the app (it's not mine), I can only change the config file.
推荐答案
使用波浪号
value="~/certificate.abc"
这篇关于如何在.config文件中指定相对于该文件的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!