11

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.

Martin Vobr
  • 5,757
  • 2
  • 37
  • 43
  • Have you found a solution? – Andrei Orlov Nov 17 '17 at 02:43
  • 1
    No. I've used alternative approach. Binding redirect is in a single source file and both debug and production configs are generated using web.config transformation. – Martin Vobr Nov 17 '17 at 10:56
  • Can you show the structure of RuntimeConfiguration.xml? I'm struggling with the same problem and I'm not sure if my RuntimeConfiguration.xml is correct – cezarypiatek Apr 19 '19 at 10:35
  • Can you show the contents of web.runtime.config? I am struggling to get this file structured properly – Nikhil Aug 28 '20 at 13:24

2 Answers2

4

I found a way to specify relative path.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <linkedConfiguration href="file:./RuntimeConfiguration.xml"/>
</assemblyBinding>
  • 2
    not sure why it was downvoted, because it is actually works. You can even remove ./ and use `file:bindings.config` –  Feb 02 '19 at 16:53
  • @JoshMouch Did you ever find a solution? we have the same exact issue right now with asp.net core 2.1 – crazy_crank Apr 08 '19 at 14:03
  • My solution was to add some code to the start of the project that made it so you no longer need the AssemblyBindings at all (or at least most of them). It handles the assembly resolve event and tells it to just use whatever version is in the BIN. See: https://stackoverflow.com/questions/325788/how-to-update-assemblybinding-section-in-config-file-at-runtime/55246142#55246142 – Josh Mouch Apr 08 '19 at 18:10
  • 1
    Relative path works for normal app.config, but not for web.config. And i found @JoshMouch 's way works greatly. – bitmountain May 11 '22 at 03:51
1

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

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