在 assemblyBinding/linkedConfiguration 元素中使用相对路径

问题描述 投票:0回答:2

我正在尝试将程序集重定向从

web.config
移动到外部文件中。原因是我想将绑定重定向保留在一处,并在调试和生产配置中使用它。

它有点有效,但我在指定相对路径方面遇到了困难。

<configuration>
   <!-- this works, but forces me to use the same path on dev and production machines -->
   <linkedConfiguration href="file://c:\data\web.runtime.config"/>

   <!-- none of those works -->
   <linkedConfiguration href="file://web.runtime.config"/>
   <linkedConfiguration href="file://..\web.runtime.config"/>
   <linkedConfiguration href="file://~/web.runtime.config"/>

</configuration>

我想将

web.runtime.config
保留在与 Web 应用程序的其余部分相同的文件夹中。是否可以在
linkedConfiguration
元素中指定相对路径?

更多信息: 我已经在 VS 2015 中使用 IIS Express 和 ASP MVC 应用程序对其进行了测试。当使用 SysInternals Process Monitor 监视文件访问时,相对路径似乎解析为

\\web.runtime.config
(无效的网络路径),而当使用绝对路径时,没有前导
\\ 
已添加。

.net binding web-config assemblybinding assembly-binding-redirect
2个回答
5
投票

我找到了一种指定相对路径的方法。

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <linkedConfiguration href="file:./RuntimeConfiguration.xml"/>
</assemblyBinding>

1
投票

文件 web.runtime.config 必须位于 bin 目录中。

使用 href="file:web.runtime.config" 就可以了

© www.soinside.com 2019 - 2024. All rights reserved.