Using relative path in assemblyBindig/linkedConfig

2020-08-22 17:38发布

I'm trying to move assembly redirects from web.config into an external file. The reason for it is that I want to keep binding redirect in one place and use it on both debug and production configurations.

It sort of works, but I'm strugling with specifying relative paths.

<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>

I want to keep the web.runtime.config in the same folder as the rest of the web application. Is it possible to specify a relative path in linkedConfiguration element?

More info: I've tested it with IIS Express and ASP MVC application in VS 2015. When monitoring file accesses using SysInternals Process Monitor relative pathes seems to resolve to \\web.runtime.config (an invalid network path), while when using the absolute path no leading \\ is added.

2条回答
叛逆
2楼-- · 2020-08-22 17:50

File web.runtime.config must be in bin dir.

And with href="file:web.runtime.config" it will be work

查看更多
等我变得足够好
3楼-- · 2020-08-22 17:58

I found a way to specify relative path.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <linkedConfiguration href="file:./RuntimeConfiguration.xml"/>
</assemblyBinding>
查看更多
登录 后发表回答