Using relative path in assemblyBindig/linkedConfiguration element
Asked Answered
C

2

12

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.

Coquillage answered 20/8, 2015 at 20:45 Comment(4)
Have you found a solution?Dink
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.Coquillage
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 correctLitchfield
Can you show the contents of web.runtime.config? I am struggling to get this file structured properlyCarleencarlen
B
5

I found a way to specify relative path.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <linkedConfiguration href="file:./RuntimeConfiguration.xml"/>
</assemblyBinding>
Battement answered 4/4, 2018 at 22:20 Comment(4)
not sure why it was downvoted, because it is actually works. You can even remove ./ and use file:bindings.configGrammatical
@JoshMouch Did you ever find a solution? we have the same exact issue right now with asp.net core 2.1Pasteup
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: #326288Gyron
Relative path works for normal app.config, but not for web.config. And i found @JoshMouch 's way works greatly.Millenarianism
B
1

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

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

Brocky answered 10/1, 2020 at 10:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.